home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap11 / howto02 / cciccfrm.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-12  |  189.6 KB  |  5,468 lines

  1. unit Cciccfrm;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, Menus, FileCtrl, CCWSock, CCICCInf,
  8.   CCICCPrf, IniFiles, Gauges , CCUUCode;
  9.  
  10. type
  11.   { This record holds the information for a number of internet connections }
  12.   PConnectionsRecord = ^TConnectionsRecord;
  13.   TConnectionsRecord = record
  14.     CProfile   : String; { Connection profile; used in lists }
  15.     CIPAddress : String; { Dotted character IP Address       }
  16.     CUserName  : String; { Login name to site; can be anonym }
  17.     CPassword  : String; { Password; won't be shown          }
  18.     CStartDir  : String; { Starting directory; used for FTP  }
  19.   end;
  20.   { Array of TCR }
  21.   CRFile = file of TConnectionsRecord; { File type for TCRec }
  22.   { This record is used to hold information about a newsgroup            }
  23.   { NOTE : hi and low pointers indicate either dl or trashing without dl }
  24.   { "read" is for an article dl'd but not trashed.                       }
  25.   PNewsGroupRecord = ^TNewsGroupRecord;
  26.   TNewsGroupRecord = record
  27.     GName                : String;  { Profile of the newsgroup              }
  28.     GRealName            : String;  { Real Newsrc name of the newsgroup     }
  29.     GLowest              : Longint; { Number of lowest dl/trashed article   }
  30.     GHighest             : Longint; { Number of highest dl/trashed article  }
  31.     GTotalNew            : Longint; { Total New articles available          }
  32.     GTotalAvailable      : Longint; { After update, shows how many arts on s}
  33.     GLowestAvailable     : Longint; { au, shows lowest a# on server         }
  34.     GHighestAvailable    : Longint; { au, shows highest a# on server        }
  35.     GPostable            : Boolean; { Can post to newsgroup                 }
  36.     GSubscribed          : Boolean; { Subscribed to newsgroup               }
  37.     GTotalArticles       : Longint; { Total articles maintained on system   }
  38.     GTotalUnReadArticles : Longint; { Total unread articles on system       }
  39.     GIDNumber            : Integer;
  40.     GFileName            : String;  { Name of file holding articles records }
  41.     GLTag                : Longint; { Tag field to hold pointer to arts TL  }
  42.   end;
  43.   NGRFile = file of TNewsGroupRecord; { File type for NGRec }
  44.   { This record is used to hold information about Newsgroup articles }
  45.   PNewsGroupArticleRecord = ^TNewsGroupArticleRecord;
  46.   TNewsGroupArticleRecord = record
  47.     NGAGroupname   : String;  { Newsgroup name (redundancy safeguard)     }
  48.     NGASubject     : String;  { Subject of article                        }
  49.     NGANumber      : Longint; { Article number                            }
  50.     NGADownloaded  : boolean; { Article attempted/succeeded downloading   }
  51.     NGASender      : String;  { Article's putative sender (CIUPKC158=us)  }
  52.     NGARead        : Boolean; { Article read flag                         }
  53.     NGAPosted      : Boolean; { Article posted flag                       }
  54.     NGAArtFileName : String;  { Name of system-gen file with article text }
  55.   end;
  56.   NGARFile = file of TNewsGroupArticleRecord;
  57.   { This record is used to hold information about EMail Mailboxes }
  58.   PEMailMailBoxRecord = ^TEMailMailBoxRecord;
  59.   TEMailMailBoxRecord = record
  60.     MBName        : String;  { Name of the mailbox                     }
  61.     MBIDNumber    : Integer;
  62.     MBMaxMsgNumber : Longint;
  63.     MBTotal       : Longint; { Total Mail Messages in Mailbox          }
  64.     MBUnReadTotal : Longint; { Total unread Mail Messages in Mailbox   }
  65.     MBUnSentTotal : Longint; { Total unsent Mail Messages in Mailbox   }
  66.     MBMsgFileName : String;  { Name of file holding Messages records   }
  67.     MBLTag        : Longint; { Tag to pointer to Tlist holding msgrecs }
  68.   end;
  69.   EMMBRFile = file of TEMailMailBoxRecord; { File type for EMMBRec }
  70.   { This record is used to hold information about EMail messages in a Mailbox }
  71.   PEMailMessageRecord = ^TEMailMessageRecord;
  72.   TEMailMessageRecord = record
  73.     MRMailBoxName      : String;  { Name of mailbox (redundancy safeguard)       }
  74.     MRMessageSubject   : String;  { Subject of the Message                       }
  75.     MRMessageRecipient : String;  { EMail address of primary recipient           }
  76.     MRMessageSender    : String;  { EMail address of sender                      }
  77.     MRCarbonCopy       : String;  { EMail CC recips; "|" delimited               }
  78.     MRBlindCarbonCopy  : String;  { EMail BCC recips; "|" delimited              }
  79.     MRDateTime         : String;  { EMail date/time field                        }
  80.     MRRead             : Boolean; { EMail Read flag                              }
  81.     MRSent             : Boolean; { EMail Send flag                              }
  82.     MRFileName         : String;  { EMail system generated filename for msg text }
  83.   end;
  84.   EMMRFile = file of TEMailMessageRecord; { File type for EMMRec }
  85.   TCCINetCCForm = class(TForm)
  86.     MainMenu1: TMainMenu;
  87.     Network1: TMenuItem;
  88.     N1: TMenuItem;
  89.     Exit1: TMenuItem;
  90.     Services1: TMenuItem;
  91.     IPAddress1: TMenuItem;
  92.     EMail1: TMenuItem;
  93.     FTP1: TMenuItem;
  94.     UsenetNws1: TMenuItem;
  95.     Panel1: TPanel;
  96.     Panel2: TPanel;
  97.     Panel3: TPanel;
  98.     Panel4: TPanel;
  99.     Panel5: TPanel;
  100.     Panel6: TPanel;
  101.     ListBox1: TListBox;
  102.     Panel7: TPanel;
  103.     SpeedButton1: TSpeedButton;
  104.     SpeedButton2: TSpeedButton;
  105.     ListBox2: TListBox;
  106.     ComboBox1: TComboBox;
  107.     Button1: TButton;
  108.     Memo1: TMemo;
  109.     Files1: TMenuItem;
  110.     Edit1: TMenuItem;
  111.     Encoding1: TMenuItem;
  112.     EMail2: TMenuItem;
  113.     FTP2: TMenuItem;
  114.     News1: TMenuItem;
  115.     Load1: TMenuItem;
  116.     Save1: TMenuItem;
  117.     Cut1: TMenuItem;
  118.     Copy1: TMenuItem;
  119.     CopytoFile1: TMenuItem;
  120.     Paste1: TMenuItem;
  121.     PastefromFile1: TMenuItem;
  122.     UUDecode1: TMenuItem;
  123.     MIMEDecode1: TMenuItem;
  124.     UUEncode1: TMenuItem;
  125.     MIMEEncode1: TMenuItem;
  126.     CheckMail1: TMenuItem;
  127.     ReplyToCurrentMessage1: TMenuItem;
  128.     SendCurrentMessage1: TMenuItem;
  129.     SendQueue1: TMenuItem;
  130.     Mailboxes1: TMenuItem;
  131.     Correspondents1: TMenuItem;
  132.     EmptyTrash1: TMenuItem;
  133.     SpeedButton4: TSpeedButton;
  134.     SpeedButton5: TSpeedButton;
  135.     SpeedButton3: TSpeedButton;
  136.     Panel8: TPanel;
  137.     Label1: TLabel;
  138.     Label2: TLabel;
  139.     ComboBox2: TComboBox;
  140.     Label3: TLabel;
  141.     ComboBox3: TComboBox;
  142.     ConnectToSite1: TMenuItem;
  143.     Disconnect1: TMenuItem;
  144.     UploadMarked1: TMenuItem;
  145.     DownloadMarked1: TMenuItem;
  146.     Directory1: TMenuItem;
  147.     ASCII1: TMenuItem;
  148.     Binary1: TMenuItem;
  149.     ASCII2: TMenuItem;
  150.     Binary2: TMenuItem;
  151.     ViewRemoteasText1: TMenuItem;
  152.     FTPSites1: TMenuItem;
  153.     CheckNewNews1: TMenuItem;
  154.     GetMarked1: TMenuItem;
  155.     CreateNewMessage1: TMenuItem;
  156.     Article1: TMenuItem;
  157.     SubscribedNewsgroups1: TMenuItem;
  158.     Trash1: TMenuItem;
  159.     Preferences1: TMenuItem;
  160.     EMail3: TMenuItem;
  161.     FTP3: TMenuItem;
  162.     News2: TMenuItem;
  163.     Label4: TLabel;
  164.     Label5: TLabel;
  165.     ViewasText1: TMenuItem;
  166.     Change1: TMenuItem;
  167.     Create1: TMenuItem;
  168.     Delete3: TMenuItem;
  169.     ChangeLocal1: TMenuItem;
  170.     OpenDialog1: TOpenDialog;
  171.     SaveDialog1: TSaveDialog;
  172.     Paths1: TMenuItem;
  173.     ProgressInfo1: TMenuItem;
  174.     N2: TMenuItem;
  175.     ViewInEditWindow1: TMenuItem;
  176.     ViewInStatusLine1: TMenuItem;
  177.     SaveToFile1: TMenuItem;
  178.     ViewWinsockInfo1: TMenuItem;
  179.     Description1: TMenuItem;
  180.     SystemStatus1: TMenuItem;
  181.     VendorSpecific1: TMenuItem;
  182.     Gauge1: TGauge;
  183.     NewsServers1: TMenuItem;
  184.     AllReadArticles1: TMenuItem;
  185.     AllMarkedArticles1: TMenuItem;
  186.     AllAvailableArticles1: TMenuItem;
  187.     NewArticle1: TMenuItem;
  188.     FollowupArticle1: TMenuItem;
  189.     Post1: TMenuItem;
  190.     CurrentArticle1: TMenuItem;
  191.     EntireQueue1: TMenuItem;
  192.     ConnectandUpdate1: TMenuItem;
  193.     Disconnect2: TMenuItem;
  194.     Headers1: TMenuItem;
  195.     RetrieveMarked1: TMenuItem;
  196.     RetrieveAll1: TMenuItem;
  197.     DownloadActiveNewsgroups1: TMenuItem;
  198.     PutinQueue1: TMenuItem;
  199.     TrashMarkedMessages1: TMenuItem;
  200.     MailServers1: TMenuItem;
  201.     ExitEMailRequired1: TMenuItem;
  202.     ToCurrentMessage1: TMenuItem;
  203.     ToNewMessage1: TMenuItem;
  204.     ToFile2: TMenuItem;
  205.     AbortNewsgroupDownload1: TMenuItem;
  206.     Catchup1: TMenuItem;
  207.     Marked1: TMenuItem;
  208.     All1: TMenuItem;
  209.     File1: TMenuItem;
  210.     SelectedArticle1: TMenuItem;
  211.     SelectMultipleArticles1: TMenuItem;
  212.     DecodeSelections1: TMenuItem;
  213.     procedure Exit1Click(Sender: TObject);
  214.     procedure FormCreate(Sender: TObject);
  215.     procedure FormDestroy(Sender: TObject);
  216.     procedure Description1Click(Sender: TObject);
  217.     procedure SystemStatus1Click(Sender: TObject);
  218.     procedure VendorSpecific1Click(Sender: TObject);
  219.     procedure ViewInEditWindow1Click(Sender: TObject);
  220.     procedure ViewInStatusLine1Click(Sender: TObject);
  221.     procedure SaveToFile1Click(Sender: TObject);
  222.     procedure IPAddress1Click(Sender: TObject);
  223.     procedure FTP1Click(Sender: TObject);
  224.     procedure FormResize(Sender: TObject);
  225.     procedure FTPSites1Click(Sender: TObject);
  226.     procedure FTP3Click(Sender: TObject);
  227.     procedure ConnectToSite1Click(Sender: TObject);
  228.     procedure Button1Click(Sender: TObject);
  229.     procedure ViewasText1Click(Sender: TObject);
  230.     procedure Disconnect1Click(Sender: TObject);
  231.     procedure ToDisplay1Click(Sender: TObject);
  232.     procedure ToFile1Click(Sender: TObject);
  233.     procedure Binary2Click(Sender: TObject);
  234.     procedure Change1Click(Sender: TObject);
  235.     procedure ChangeLocal1Click(Sender: TObject);
  236.     procedure ListBox1DblClick(Sender: TObject);
  237.     procedure ListBox2DblClick(Sender: TObject);
  238.     procedure ASCII1Click(Sender: TObject);
  239.     procedure DeleteRemoteFiles1Click(Sender: TObject);
  240.     procedure Binary1Click(Sender: TObject);
  241.     procedure Delete3Click(Sender: TObject);
  242.     procedure Create1Click(Sender: TObject);
  243.     procedure ListBox1Click(Sender: TObject);
  244.     procedure UsenetNws1Click(Sender: TObject);
  245.     procedure Disconnect2Click(Sender: TObject);
  246.     procedure News2Click(Sender: TObject);
  247.     procedure ConnectandUpdate1Click(Sender: TObject);
  248.     procedure CheckNewNews1Click(Sender: TObject);
  249.     procedure NewsServers1Click(Sender: TObject);
  250.     procedure SubscribedNewsgroups1Click(Sender: TObject);
  251.     procedure RetrieveMarked1Click(Sender: TObject);
  252.     procedure RetrieveAll1Click(Sender: TObject);
  253.     procedure GetMarked1Click(Sender: TObject);
  254.     procedure NewArticle1Click(Sender: TObject);
  255.     procedure FollowupArticle1Click(Sender: TObject);
  256.     procedure PutinQueue1Click(Sender: TObject);
  257.     procedure CurrentArticle1Click(Sender: TObject);
  258.     procedure EntireQueue1Click(Sender: TObject);
  259.     procedure AllReadArticles1Click(Sender: TObject);
  260.     procedure AllMarkedArticles1Click(Sender: TObject);
  261.     procedure AllAvailableArticles1Click(Sender: TObject);
  262.     procedure DownloadActiveNewsgroups1Click(Sender: TObject);
  263.     procedure UUEncode1Click(Sender: TObject);
  264.     procedure Load1Click(Sender: TObject);
  265.     procedure Save1Click(Sender: TObject);
  266.     procedure EMail1Click(Sender: TObject);
  267.     procedure CheckMail1Click(Sender: TObject);
  268.     procedure MailServers1Click(Sender: TObject);
  269.     procedure EMail3Click(Sender: TObject);
  270.     procedure Paths1Click(Sender: TObject);
  271.     procedure ExitEMailRequired1Click(Sender: TObject);
  272.     procedure Cut1Click(Sender: TObject);
  273.     procedure Copy1Click(Sender: TObject);
  274.     procedure CopytoFile1Click(Sender: TObject);
  275.     procedure Paste1Click(Sender: TObject);
  276.     procedure PastefromFile1Click(Sender: TObject);
  277.     procedure SpeedButton5Click(Sender: TObject);
  278.     procedure SpeedButton1Click(Sender: TObject);
  279.     procedure SpeedButton2Click(Sender: TObject);
  280.     procedure ListBox2Click(Sender: TObject);
  281.     procedure AbortNewsgroupDownload1Click(Sender: TObject);
  282.     procedure Marked1Click(Sender: TObject);
  283.     procedure All1Click(Sender: TObject);
  284.     procedure File1Click(Sender: TObject);
  285.     procedure SelectedArticle1Click(Sender: TObject);
  286.     procedure SelectMultipleArticles1Click(Sender: TObject);
  287.     procedure DecodeSelections1Click(Sender: TObject);
  288.     procedure SpeedButton4Click(Sender: TObject);
  289.   private
  290.     { Private declarations }
  291.   public
  292.     { Public declarations }
  293.     procedure EnableFTPMenus;
  294.     procedure DisableFTPMenus;
  295.     procedure EnableNNTPMenus;
  296.     procedure DisableNNTPMenus;
  297.     procedure EnablePOP3SMTPMenus;
  298.     procedure DisablePOP3SMTPMenus;
  299.     procedure UpdateGauge( BytesFinished , TotalToHandle : longint );
  300.     procedure UpdateMailGauge( BytesFinished , TotalToHandle : longint );
  301.     procedure UpdateUUGauge( BytesFinished , TotalToHandle : longint );
  302.     function DoFTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  303.     function DoNNTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  304.     function DoPOP3Connection( PCRPointer : PConnectionsRecord ) : boolean;
  305.     procedure DoFTPDisconnect;
  306.     procedure DoNNTPDisconnect;
  307.     procedure DoPOP3SMTPDisconnect;
  308.     procedure ReadIniData;
  309.     procedure WriteIniData;
  310.     procedure LoadFTPSiteFile;
  311.     procedure LoadNNTPSiteFile;
  312.     procedure LoadEmailServerFile;
  313.     procedure SaveEMailServerFile;
  314.     procedure LoadEmailMailboxFile( WhichServer : Integer );
  315.     procedure SaveEMailMailboxFile( WhichServer : Integer );
  316.     procedure LoadEmailCorrespondentsFile;
  317.     procedure SaveEMailCorrespondentsFile;
  318.     procedure SetupEMailServerStatus;
  319.     procedure SetupNNTPServersInfoDisplay;
  320.     procedure SaveFTPSiteFile;
  321.     procedure SetupFTPSiteLists;
  322.     procedure SaveNNTPSiteFile;
  323.     procedure SetupNNTPSiteLists;
  324.     procedure SetupNNTPNewsGroupsInfoDisplay;
  325.     procedure SetupNNTPNewsGroupLists;
  326.     procedure SaveNNTPNewsGroupLists;
  327.     procedure SetupNewsGroupListboxes;
  328.     procedure SetupEMailListboxes;
  329.     procedure SetupMailboxLists;
  330.     procedure SetupEMailServersInfoDisplay;
  331.     procedure SetupEMailMailboxInfoDisplay;
  332.     procedure PopulateLB2WithArticleHeaders;
  333.     procedure PopulateLB2WithMessageHeaders;
  334.     procedure SetupEMailCorrespondentsInfoDisplay;
  335.     procedure AddNullTermTextToMemo( TheTextToAdd   : String;
  336.                                      TheMemoToAddTo : TMemo   );
  337.     function AddNullTermTextToLabel( TheTextToAdd   : String ) : String;
  338.     procedure SetHGCursors;
  339.     procedure SetNormalCursors;
  340.     procedure AddProgressText( WhatText : String );
  341.     procedure ShowProgressText( WhatText : String );
  342.     procedure ShowProgressErrorText( WhatText : String );
  343.     procedure SocketsErrorOccurred( Sender     : TObject;
  344.                                      ErrorCode  : Integer;
  345.                                      TheMessage : String   );
  346.   end;
  347.   { Component to hold FTP handling capabilities }
  348.   TFTPComponent = class( TWinControl )
  349.   public
  350.     FTPCommandInProgress ,
  351.     Connection_Established : Boolean;
  352.     Socket1 : TCCSocket;
  353.     Socket2 : TCCSocket;
  354.     constructor Create( AOwner : TComponent ); override;
  355.     destructor Destroy; override;
  356.     function GetTotalBytesToReceive( TheString : String ) : Longint;
  357.     function StripBrackets( TheString : String ) : String;
  358.     function GetShortPathname( TheString : String ) : String;
  359.     function GetWin16FileName( InputName : String ) : String;
  360.     function GetRemoteWorkingDirectory( var RemoteDir : String ) : Boolean;
  361.     function SetRemoteDirectory( TheDir : String ) : Boolean;
  362.     function DeleteRemoteDirectory( TheDir : String ) : Boolean;
  363.     function CreateRemoteDirectory( TheDir : String ) : Boolean;
  364.     function DeleteRemoteFile( TheFileName : String ) : Boolean;
  365.     function EstablishConnection( PCRPointer : PConnectionsRecord ) : Boolean;
  366.     function LoginUser( PCRPointer : PConnectionsRecord ) : Boolean;
  367.     function SendPassword( PCRPointer : PConnectionsRecord ) : Boolean;
  368.     function SetRemoteStartupDirectory( PCRPointer : PConnectionsRecord )
  369.               : Boolean;
  370.     function GetRemoteDirectoryListing( TheListBox : TListBox ) : Boolean;
  371.     function GetRemoteDirectoryListingToMemo : Boolean;
  372.     procedure SendASCIILocalFile( LocalName : String );
  373.     procedure SendBinaryLocalFile( LocalName : String );
  374.     procedure ReceiveASCIIRemoteFile( RemoteName , LocalName : String );
  375.     procedure ReceiveBinaryRemoteFile( RemoteName , LocalName : String );
  376.     function GetLocalDirectoryAndListing( var TheString : String;
  377.                                               TheListBox : TListBox )
  378.               : Boolean;
  379.     function GetUNIXTextString( var StringIn : String ) : String;
  380.     procedure ReceiveASCIIRemoteFileToMemo( RemoteName : String );
  381.     function GetListeningPort : Integer;
  382.     procedure GetFileNameFromUNIXFileName( var TheName : String );
  383.     function Disconnect : Boolean;
  384.     function DoCStyleFormat(       TheText      : string;
  385.                              const TheArguments : array of const ) : String;
  386.     procedure UpdateGauge( BytesFinished , TotalToHandle : longint );
  387.     function GetQuotedString( TheString : String ) : String;
  388.     procedure AddProgressText( WhatText : String );
  389.     procedure ShowProgressText( WhatText : String );
  390.     procedure ShowProgressErrorText( WhatText : String );
  391.     function GetFTPServerResponse( var ResponseString : String ) : integer;
  392.     procedure FTPSocketsErrorOccurred( Sender     : TObject;
  393.                                      ErrorCode  : Integer;
  394.                                      TheMessage : String   );
  395.     function PerformFTPCommand(
  396.                     TheCommand   : string;
  397.               const TheArguments : array of const ) : Integer;
  398.   end;
  399. const
  400.   POV_MEMO                 = 1; { Progress to the Memo           }
  401.   POV_STAT                 = 2; { Progress to the status caption }
  402.   TCPIP_STATUS_PRELIMINARY   = 1; { Wait; command being processed  }
  403.   TCPIP_STATUS_COMPLETED     = 2; { Done; command fully succeded   }
  404.   TCPIP_STATUS_CONTINUING    = 3; { OK; send more data to finish   }
  405.   TCPIP_STATUS_RETRY_COMMAND = 4; { Temporary Error; try cmd again }
  406.   TCPIP_STATUS_FATAL_ERROR   = 5; { Fatal Error; don't retry cmd   }
  407.  
  408. var
  409.   CCINetCCForm         : TCCINetCCForm;
  410.   GlobalErrorCode      : Integer;        { Used to pass around error info  }
  411.   GlobalAbortedFlag    : Boolean;        { Used to signal timeout error    }
  412.   ProgressList         : TStringList;    { Used to hold progress text info }
  413.   ProgressFileName     : String;         { Used to hold progress file name }
  414.   ProgressOutputVector : Integer;        { Used to direct progress output  }
  415.   TheFTPSiteList       : TList;          { Used to store the FTP site recs }
  416.   TheWorkingFTPSL      : TList;          { Used to store working copy of l }
  417.   TheNewsServerList    : TList;          { Used to hold list of NNTP servs }
  418.   TheWorkingNSSL       : TList;          { Used for working copy of above  }
  419.   TheEMailServerList   : TList;          { Used for list of POP3/SMTP serv }
  420.   TheWorkingEMSL       : TList;          { Used for working copy of above  }
  421.   TheNewsRCList        : TList;          { Used for list of available ngs  }
  422.   TheWorkingNRCSL      : TList;          { Used for working copy of above  }
  423.   TheNGArticlesList    : TList;          { Used for current articles list  }
  424.                                          { (will hot swap from pointer of  }
  425.                                          {  Tlist of Tlists in base rec.)  }
  426.   TheEMailMailboxList  : TList;          { Used for list of available mbs  }
  427.   TheWorkingMBSL       : TList;          { Used for working copy of above  }
  428.   TheCorrespondentsList: TList;          { Used for list of correspondents }
  429.   TheWorkingCPSL       : TList;          { Used for working copy of above  }
  430.   TheMBMessagesList    : TList;          { Used for current msgs; hotswaps }
  431.   TheEMailServerFile   : CRFile;         { File of Email servers records   }
  432.   TheEMailCorrespondentsFile : CRFile;
  433.   TheNewsServerFile    : CRFile;         { File of NNTP servers records    }
  434.   TheNewsRCFile        : NGRFile;        { File of Newsgroups records      }
  435.   TheNewsArticleFile   : NGARFile;       { Current ng articles records file}
  436.   TheEMailMailboxFile  : EMMBRFile;      { File of Mailboxes records       }
  437.   TheEMailMessagesFile : EMMRFile;       { Current mb messages records file}
  438.   TheFTPSiteFile       : CRFile;         { Used to load the FTP site file  }
  439.   TheICCIniFile        : TIniFile;       { Used to retrieve the INI File   }
  440.   MailPath             : String;         { Used for path to Mail Files     }
  441.   NewsPath             : String;         { Used for path to News Files     }
  442.   FTPPath              : String;         { Used for path to FTP Files      }
  443.   CurrentPassWordString : String;        { Used to hold login id for anons }
  444.   CurrentEMPassWordString : String;      { Used to hold login id for anons }
  445.   PassWordControlVector : Integer;       { Used to hold display of pw vect }
  446.   CurrentRealPWString   : String;        { Used to hold a real password    }
  447.   EMPassWordControlVector : Integer;       { Used to hold display of pw vect }
  448.   CurrentEMRealPWString   : String;        { Used to hold a real password    }
  449.   TheFTPComponent       : TFTPComponent; { FTP Object                      }
  450.   TheLine ,
  451.   HolderLine ,
  452.   GlobalTextBuffer      : String;
  453.   TheAnonRedialVector ,
  454.   DefaultDownloadVector : Integer;
  455.   NewsReadArticlePurgingVector : Integer;
  456.   NewsPostQueueingVector : Integer;
  457.   NewsReadArticleDisplayVector : Integer;
  458.   NewsUUMIMEVector : Integer;
  459.   NewsInitialUpdateVector : Integer;
  460.   LeftoverText          : String;
  461.   LeftoversOnTable      : Boolean;
  462.   FileNameToXFer        : String;
  463.   WhichServer           : Integer;       { Holds current NNTP server }
  464.   WhichGroup            : Integer;       { Holds current NNTP newsgroup }
  465.   TheUUObject           : TUUCodingObject;
  466.   EMRemoteDeletionVector : Integer;
  467.   EMChokeVector : Integer;
  468.   EMDefaultDownloadVector : Integer;
  469.   EMQueueVector : Integer;
  470.   NewsgroupListLoaded ,
  471.   EmailLoaded ,
  472.   NewMessageInProgress : Boolean;
  473.   TheUUDecodeList      : TStringList;
  474.   
  475. implementation
  476.  
  477. uses CCICCPOP, CCICNNTP;
  478.  
  479. var
  480.   TheNNTPComponent      : TNNTPComponent;{ NNTP News Object                }
  481.  
  482. {$R *.DFM}
  483.  
  484.  
  485. { This procedure actually attempts to connect to the internet at an POP3SMTP site }
  486. function TCCINetCCForm.DoPOP3Connection( PCRPointer : PConnectionsRecord ) : boolean;
  487. begin
  488.   { Create the component }
  489.   Result := false;
  490.   { Do busy cursors }
  491.   SetHGCursors;
  492.   if not ThePOP3SMTPComponent.EstablishPOP3Connection( PCRPointer ) then
  493.   begin
  494.     { Do saved cursors }
  495.     ThePOP3SMTPComponent.POP3CommandInProgress := false;
  496.     ThePOP3SMTPComponent.Connection_Established := false;
  497.     SetNormalCursors;
  498.     exit;
  499.   end;
  500.   if not ThePOP3SMTPComponent.LoginUser( PCRPointer ) then
  501.   begin
  502.     { Do saved cursors }
  503.     ThePOP3SMTPComponent.POP3CommandInProgress := false;
  504.     ThePOP3SMTPComponent.Connection_Established := false;
  505.     SetNormalCursors;
  506.     exit;
  507.   end;
  508.   if not ThePOP3SMTPComponent.SendPassword( PCRPointer ) then
  509.   begin
  510.     { Do saved cursors }
  511.     ThePOP3SMTPComponent.POP3CommandInProgress := false;
  512.     ThePOP3SMTPComponent.Connection_Established := false;
  513.     SetNormalCursors;
  514.     exit;
  515.   end;
  516.   SetNormalCursors;
  517.   Result := true;
  518.   EnablePOP3SMTPMenus;
  519.   ThePOP3SMTPComponent.POP3CommandInProgress := false;
  520.   Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  521. end;
  522.  
  523. { This procedure actually attempts to disconnect to the internet at an ftp site}
  524. procedure TCCINetCCForm.DoPOP3SMTPDisconnect;
  525. begin
  526.   { Kill the socket }
  527.   ThePOP3SMTPComponent.Socket1.CCSockClose;
  528.   ThePOP3SMTPComponent.Connection_Established := false;
  529. end;
  530.  
  531. { Procedure to load the POP3SMTP Site list }
  532. procedure TCCINetCCForm.LoadEmailServerFile;
  533. var ThePSSRecord : PConnectionsRecord; { Generic TCR Pointer    }
  534.     PSSLName     : String;             { POP3SMTP Site List filename }
  535.     Counter_1    : Integer;            { Loop counter           }
  536. begin
  537.   { Create the sites list list }
  538.   TheEMailServerList := TList.Create;
  539.   { Set up the FTP sites list file name }
  540.   PSSLName := MailPath + '\PSSERVER.TCR';
  541.   { If the FTP Site List exists load it in }
  542.   if FileExists( PSSLName ) then
  543.   begin
  544.     { set up the file and open it }
  545.     AssignFile( TheEMailServerFile , PSSLName );
  546.     Reset( TheEMailServerFile );
  547.     { read in the records }
  548.     for Counter_1 := 0 to FileSize( TheEMailServerFile ) - 1 do
  549.     begin
  550.       { Create the TCRecord }
  551.       New( ThePSSRecord );
  552.       { Read in the data record }
  553.       Seek( TheEMailServerFile , Counter_1 );
  554.       Read( TheEMailServerFile , ThePSSRecord^ );
  555.       { Add the record to the list }
  556.       TheEMailServerList.Add( ThePSSRecord );
  557.     end;
  558.     { close the file }
  559.     CloseFile( TheEMailServerFile );
  560.   end
  561.   else
  562.   { Otherwise create a default one with the a generic mail site (?) }
  563.   begin
  564.     { create new record }
  565.     New( ThePSSRecord );
  566.     { fill in its info }
  567.     with ThePSSRecord^ do
  568.     begin
  569.       CProfile   := 'My Mail Server';
  570.       CIPAddress := 'mail.myprovider.com';
  571.       CUserName  := 'myname';
  572.       CPassword  := 'mypassword';
  573.       CStartDir  := 'myname@myprovider.com';
  574.     end;
  575.     { add it to the list }
  576.     { do it three more times }
  577.     TheEMailServerList.Add( ThePSSRecord );
  578.     { create the file and write out the data, then close it }
  579.     AssignFile( TheEMailServerFile , PSSLName );
  580.     Rewrite( TheEMailServerFile );
  581.     ThePSSRecord :=
  582.        PConnectionsRecord( TheEMailServerList.Items[ 0 ] );
  583.       Seek( TheEMailServerFile , 0 );
  584.       Write( TheEMailServerFile , ThePSSRecord^ );
  585.     CloseFile( TheEMailServerFile );
  586.   end;
  587.   TheWorkingEMSL := TList.Create;
  588.   For Counter_1 := 0 to TheEMailServerList.Count - 1 do
  589.   begin
  590.     New( ThePSSRecord );
  591.     ThePSSRecord^ := PConnectionsRecord( TheEMailServerList.Items[ Counter_1 ] )^;
  592.     TheWorkingEMSL.Add( ThePSSRecord );
  593.   end;
  594. end;
  595.  
  596. procedure TCCINetCCForm.SaveEMailServerFile;
  597. var ThePSSRecord : PConnectionsRecord; { The TC Record pointer   }
  598.     PSSLName     : String;             { POP3SMTP Site List filename }
  599.     Counter_1    : Integer;            { Loop counter           }
  600. begin
  601.   { Set up the file name }
  602.   PSSLName := MailPath + '\PSSERVER.TCR';
  603.   { Assign the file }
  604.   AssignFile( TheEMailServerFile , PSSLName );
  605.   { Rewrite it }
  606.   Rewrite( TheEMailServerFile );
  607.   { run the list through the procedure }
  608.   for Counter_1 := 0 to TheEMailServerList.Count - 1 do
  609.   begin
  610.     { get the record from the list }
  611.     ThePSSRecord :=
  612.      PConnectionsRecord( TheEMailServerList.Items[ Counter_1 ] );
  613.     { Do the seek/write }
  614.     Seek( TheEMailServerFile , Counter_1 );
  615.     Write( TheEMailServerFile , ThePSSRecord^ );
  616.     { free the record }
  617.     Dispose( ThePSSRecord );
  618.   end;
  619.   { Close the file }
  620.   CloseFile( TheEMailServerFile );
  621.   { Free the list pointers }
  622.   TheEMailServerList.Free;
  623.   for Counter_1 := 0 to TheWorkingEMSL.Count - 1 do
  624.   begin
  625.     ThePSSRecord := PConnectionsRecord( TheWorkingEMSL.Items[ Counter_1 ] );
  626.     Dispose( ThePSSRecord );
  627.   end;
  628.   TheWorkingEMSL.Free;
  629. end;
  630.  
  631. { Procedure to load the POP3SMTP Site list }
  632. procedure TCCINetCCForm.LoadEmailMailboxFile( WhichServer : Integer );
  633. var TheMBRecord : PEMailMailboxRecord; { Generic TCR Pointer    }
  634.     PSMBName    : String;              { Mailbox filename       }
  635.     Counter_1   ,
  636.     Counter_2   : Integer;             { Loop counter           }
  637.     TheMessagesList : TList;
  638.     TheEMMRecord : PEMailMessageRecord;
  639. begin
  640.   { Create the sites list list }
  641.   TheEMailMailboxList := TList.Create;
  642.   { Set up the FTP sites list file name }
  643.   PSMBName := MailPath + '\MAILBX' + IntToStr( WhichServer ) + '.MBX';
  644.   { If the FTP Site List exists load it in }
  645.   if FileExists( PSMBName ) then
  646.   begin
  647.     { set up the file and open it }
  648.     AssignFile( TheEMailMailboxFile , PSMBName );
  649.     Reset( TheEMailMailboxFile );
  650.     { read in the records }
  651.     for Counter_1 := 0 to FileSize( TheEMailMailboxFile ) - 1 do
  652.     begin
  653.       { Create the TCRecord }
  654.       New( TheMBRecord );
  655.       { Read in the data record }
  656.       Seek( TheEMailMailboxFile , Counter_1 );
  657.       Read( TheEMailMailboxFile , TheMBRecord^ );
  658.       { Add the record to the list }
  659.       TheEMailMailboxList.Add( TheMBRecord );
  660.     end;
  661.     { close the file }
  662.     CloseFile( TheEMailMailboxFile );
  663.   end
  664.   else
  665.   { Otherwise create a default one with the In and Out mailboxes (?) }
  666.   begin
  667.     { create new record }
  668.     New( TheMBRecord );
  669.     { fill in its info }
  670.     with TheMBRecord^ do
  671.     begin
  672.       MBName         := 'In Box';
  673.       MBIDNumber     := 1;
  674.       MBMaxMsgNumber := 0;
  675.       MBTotal        := 0;
  676.       MBUnReadTotal  := 0;
  677.       MBUnSentTotal  := 0;
  678.       MBMsgFileName  := 'MB1.MBX';
  679.       MBLTag         := 0;
  680.     end;
  681.     { add it to the list }
  682.     TheEMailMailboxList.Add( TheMBRecord );
  683.     { create new record }
  684.     New( TheMBRecord );
  685.     { fill in its info }
  686.     with TheMBRecord^ do
  687.     begin
  688.       MBName         := 'Out Box';
  689.       MBIDNumber     := 2;
  690.       MBMaxMsgNumber := 0;
  691.       MBTotal        := 0;
  692.       MBUnReadTotal  := 0;
  693.       MBUnSentTotal  := 0;
  694.       MBMsgFileName  := 'MB2.MBX';
  695.       MBLTag         := 0;
  696.     end;
  697.     { add it to the list }
  698.     TheEMailMailboxList.Add( TheMBRecord );
  699.     { create the file and write out the data, then close it }
  700.     AssignFile( TheEMailMailboxFile , PSMBName );
  701.     Rewrite( TheEMailMailboxFile );
  702.     TheMBRecord :=
  703.        PEMailMailboxRecord( TheEMailMailboxList.Items[ 0 ] );
  704.       Seek( TheEMailMailboxFile , 0 );
  705.       Write( TheEMailMailboxFile , TheMBRecord^ );
  706.     TheMBRecord :=
  707.        PEMailMailboxRecord( TheEMailMailboxList.Items[ 1 ] );
  708.       Seek( TheEMailMailboxFile , 1 );
  709.       Write( TheEMailMailboxFile , TheMBRecord^ );
  710.     CloseFile( TheEMailMailboxFile );
  711.   end;
  712.   { Load in Message Records and create storage lists }
  713.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  714.   begin
  715.     PSMBName := PEMailMailboxRecord(
  716.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBMsgFileName;
  717.     if FileExists( MailPath + '\' + PSMBName ) then
  718.     begin
  719.       TheMessagesList := TList.Create;
  720.       AssignFile( TheEMailMessagesFile , MailPath + '\' + PSMBName );
  721.       Reset( TheEMailMessagesFile );
  722.       for Counter_2 := 0 to FileSize( TheEMailMessagesFile ) - 1 do
  723.       begin
  724.         New( TheEMMRecord );
  725.         Seek( TheEMailMessagesFile , Counter_2 );
  726.         Read( TheEMailMessagesFile , TheEMMRecord^ );
  727.         TheMessagesList.Add( TheEMMRecord );
  728.       end;
  729.       CloseFile( TheEMailMessagesFile );
  730.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  731.        Longint( TheMessagesList );
  732.     end
  733.     else
  734.     begin
  735.       TheMessagesList := TList.Create;
  736.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  737.        Longint( TheMessagesList );
  738.     end;
  739.   end;
  740.   TheWorkingMBSL := TList.Create;
  741.   For Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  742.   begin
  743.     New( TheMBRecord );
  744.     TheMBRecord^ := PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^;
  745.     TheWorkingMBSL.Add( TheMBRecord );
  746.   end;
  747. end;
  748.  
  749. procedure TCCINetCCForm.SaveEMailMailboxFile( WhichServer : Integer );
  750. var TheMBRecord : PEMailMailboxRecord; { Generic TCR Pointer    }
  751.     PSMBName    : String;              { Mailbox filename       }
  752.     Counter_2 ,
  753.     Counter_1   : Integer;             { Loop counter           }
  754.     TheList     : TList;
  755.     TheEMMRecord : PEMailMessageRecord;
  756. begin
  757.   { Load in Message Records and create storage lists }
  758.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  759.   begin
  760.     PSMBName := PEMailMailboxRecord(
  761.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBMsgFileName;
  762.     TheList := TList( PEMailMailboxRecord(
  763.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag );
  764.     AssignFile( TheEMailMessagesFile , Mailpath + '\' + PSMBName );
  765.     Rewrite( TheEMailMessagesFile );
  766.     for Counter_2 := 0 to TheList.Count - 1 do
  767.     begin
  768.       TheEMMRecord := PEMailMessageRecord( TheList.Items[ Counter_2 ] );
  769.       Seek( TheEMailMessagesFile , Counter_2 );
  770.       Write( TheEMailMessagesFile , TheEMMRecord^ );
  771.       Dispose( TheEMMRecord );
  772.     end;
  773.     CloseFile( TheEMailMessagesFile );
  774.     TheList.Free;
  775.   end;
  776.   { Set up the file name }
  777.   PSMBName := MailPath + '\MAILBX' + IntToStr( WhichServer ) + '.MBX';
  778.   { Assign the file }
  779.   AssignFile( TheEMailMailboxFile , PSMBName );
  780.   { Rewrite it }
  781.   Rewrite( TheEMailMailboxFile );
  782.   { run the list through the procedure }
  783.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  784.   begin
  785.     { get the record from the list }
  786.     TheMBRecord :=
  787.      PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] );
  788.     { Do the seek/write }
  789.     Seek( TheEMailMailboxFile , Counter_1 );
  790.     Write( TheEMailMailboxFile , TheMBRecord^ );
  791.     { free the record }
  792.     Dispose( TheMBRecord );
  793.   end;
  794.   { Close the file }
  795.   CloseFile( TheEMailMailboxFile );
  796.   { Free the list pointers }
  797.   TheEMailMailboxList.Free;
  798.   for Counter_1 := 0 to TheWorkingMBSL.Count - 1 do
  799.   begin
  800.     TheMBRecord := PEMailMailboxRecord( TheWorkingMBSL.Items[ Counter_1 ] );
  801.     Dispose( TheMBRecord );
  802.   end;
  803.   TheWorkingMBSL.Free;
  804. end;
  805.  
  806. { Procedure to load the POP3SMTP Site list }
  807. procedure TCCINetCCForm.LoadEmailCorrespondentsFile;
  808. var ThePSSRecord : PConnectionsRecord; { Generic TCR Pointer    }
  809.     PSSLName     : String;             { POP3SMTP Site List filename }
  810.     Counter_1    : Integer;            { Loop counter           }
  811. begin
  812.   { Create the sites list list }
  813.   TheCorrespondentsList := TList.Create;
  814.   { Set up the FTP sites list file name }
  815.   PSSLName := MailPath + '\PSCORRSP.TCR';
  816.   { If the FTP Site List exists load it in }
  817.   if FileExists( PSSLName ) then
  818.   begin
  819.     { set up the file and open it }
  820.     AssignFile( TheEMailCorrespondentsFile , PSSLName );
  821.     Reset( TheEMailCorrespondentsFile );
  822.     { read in the records }
  823.     for Counter_1 := 0 to FileSize( TheEMailCorrespondentsFile ) - 1 do
  824.     begin
  825.       { Create the TCRecord }
  826.       New( ThePSSRecord );
  827.       { Read in the data record }
  828.       Seek( TheEMailCorrespondentsFile , Counter_1 );
  829.       Read( TheEMailCorrespondentsFile , ThePSSRecord^ );
  830.       { Add the record to the list }
  831.       TheCorrespondentsList.Add( ThePSSRecord );
  832.     end;
  833.     { close the file }
  834.     CloseFile( TheEMailCorrespondentsFile );
  835.   end
  836.   else
  837.   { Otherwise create a default one with the author }
  838.   begin
  839.     { create new record }
  840.     New( ThePSSRecord );
  841.     { fill in its info }
  842.     with ThePSSRecord^ do
  843.     begin
  844.       CProfile   := 'Nathan Wallace at TDE';
  845.       CIPAddress := 'kilgalen@tde.com';
  846.       CUserName  := '';
  847.       CPassword  := '';
  848.       CStartDir  := '';
  849.     end;
  850.     { add it to the list }
  851.     { do it three more times }
  852.     TheCorrespondentsList.Add( ThePSSRecord );
  853.     { create the file and write out the data, then close it }
  854.     AssignFile( TheEMailCorrespondentsFile , PSSLName );
  855.     Rewrite( TheEMailCorrespondentsFile );
  856.     ThePSSRecord :=
  857.        PConnectionsRecord( TheCorrespondentsList.Items[ 0 ] );
  858.       Seek( TheEMailCorrespondentsFile , 0 );
  859.       Write( TheEMailCorrespondentsFile , ThePSSRecord^ );
  860.     CloseFile( TheEMailCorrespondentsFile );
  861.   end;
  862.   TheWorkingCPSL := TList.Create;
  863.   For Counter_1 := 0 to TheCorrespondentsList.Count - 1 do
  864.   begin
  865.     New( ThePSSRecord );
  866.     ThePSSRecord^ := PConnectionsRecord( TheCorrespondentsList.Items[ Counter_1 ] )^;
  867.     TheWorkingCPSL.Add( ThePSSRecord );
  868.   end;
  869.   CCInetCCForm.ComboBox2.Clear;
  870.   CCInetCCForm.ComboBox3.Clear;
  871.   { Add the new info }
  872.   for Counter_1 := 0 to TheWorkingCPSL.Count - 1 do
  873.   begin
  874.     CCINetCCForm.ComboBox2.Items.Add( PConnectionsRecord(
  875.      TheCorrespondentsList.Items[ Counter_1 ] )^.CProfile );
  876.     CCINetCCForm.ComboBox3.Items.Add( PConnectionsRecord(
  877.      TheCorrespondentsList.Items[ Counter_1 ] )^.CProfile );
  878.   end;
  879.   CCINetCCForm.ComboBox2.ItemIndex := 0;
  880.   CCINetCCForm.ComboBox3.ItemIndex := 0;
  881. end;
  882.  
  883. procedure TCCINetCCForm.SaveEMailCorrespondentsFile;
  884. var ThePSSRecord : PConnectionsRecord; { The TC Record pointer   }
  885.     PSSLName     : String;             { POP3SMTP Site List filename }
  886.     Counter_1    : Integer;            { Loop counter           }
  887. begin
  888.   { Set up the file name }
  889.   PSSLName := MailPath + '\PSCORRSP.TCR';
  890.   { Assign the file }
  891.   AssignFile( TheEMailCorrespondentsFile , PSSLName );
  892.   { Rewrite it }
  893.   Rewrite( TheEMailCorrespondentsFile );
  894.   { run the list through the procedure }
  895.   for Counter_1 := 0 to TheCorrespondentsList.Count - 1 do
  896.   begin
  897.     { get the record from the list }
  898.     ThePSSRecord :=
  899.      PConnectionsRecord( TheCorrespondentsList.Items[ Counter_1 ] );
  900.     { Do the seek/write }
  901.     Seek( TheEMailCorrespondentsFile , Counter_1 );
  902.     Write( TheEMailCorrespondentsFile , ThePSSRecord^ );
  903.     { free the record }
  904.     Dispose( ThePSSRecord );
  905.   end;
  906.   { Close the file }
  907.   CloseFile( TheEMailCorrespondentsFile );
  908.   { Free the list pointers }
  909.   TheCorrespondentsList.Free;
  910.   for Counter_1 := 0 to TheWorkingCPSL.Count - 1 do
  911.   begin
  912.     ThePSSRecord := PConnectionsRecord( TheWorkingCPSL.Items[ Counter_1 ] );
  913.     Dispose( ThePSSRecord );
  914.   end;
  915.   TheWorkingCPSL.Free;
  916. end;
  917.  
  918. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  919. procedure TCCINetCCForm.SetupEMailServerStatus;
  920. begin
  921.   { Set up display for main form }
  922.   CCINetCCForm.Tag := 6; { Email Tag }
  923.   CCINetCCForm.Caption := 'CC Internet Command Center -- EMail Mode';
  924.   CCINetCCForm.ViewWinsockInfo1.Enabled := false;
  925.   CCINetCCForm.EMail2.Enabled := true;
  926.   CCINetCCForm.EMail1.Enabled := false;
  927.   CCINetCCForm.UsenetNws1.Enabled := false;
  928.   CCINetCCForm.FTP1.Enabled := false;
  929.   CCINetCCForm.Label1.Caption := 'Mail Server:';
  930.   CCINetCCForm.Button1.Caption := 'New Mail';
  931.   CCINetCCForm.Label4.Caption := 'Mailboxes';
  932.   CCINetCCForm.Label5.Caption := 'Messages';
  933. end;
  934.  
  935. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  936. procedure TCCINetCCForm.SetupMailboxLists;
  937. var TheEMMRecord : PEMailMessageRecord; {  }
  938.     Counter_1 ,
  939.     Counter_2    : Integer;             {  }
  940.     EMMFileName  : String;              {  }
  941.     WorkingList  : TList;
  942. begin
  943.   { Abort if no server to select }
  944.   if ComboBox1.ItemIndex = -1 then exit;
  945.   { Get number of server in list }
  946.   WhichServer := ComboBox1.ItemIndex;
  947.   { Load in mailbox data }
  948.   LoadEmailMailboxFile( WhichServer );
  949.   { Load in Mailbox Records and create storage lists }
  950.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  951.   begin
  952.     EMMFileName := PEMailMailboxRecord(
  953.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBMsgFileName;
  954.     if FileExists( MailPath + '\' + EMMFileName ) then
  955.     begin
  956.       WorkingList := TList.Create;
  957.       AssignFile( TheEMailMessagesFile , EMMFileName );
  958.       Reset( TheEMailMessagesFile );
  959.       for Counter_2 := 0 to FileSize( TheEMailMessagesFile ) - 1 do
  960.       begin
  961.         New( TheEMMRecord );
  962.         Seek( TheEMailMessagesFile , Counter_2 );
  963.         Read( TheEMailMessagesFile , TheEMMRecord^ );
  964.         WorkingList.Add( TheEMMRecord );
  965.       end;
  966.       CloseFile( TheEMailMessagesFile );
  967.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  968.        Longint( WorkingList );
  969.     end
  970.     else
  971.     begin
  972.       WorkingList := TList.Create;
  973.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  974.        Longint( WorkingList );
  975.     end;
  976.   end;
  977. end;
  978.  
  979. { This procedure populates LB2 with article subjects for any }
  980. { available articles for a given newsgroup.                  }
  981. procedure TCCINetCCForm.PopulateLB2WithMessageHeaders;
  982. var Counter_1    : Integer;
  983.     TheEMMRecord : PEMailMessageRecord;
  984.     TempString   : String;
  985. begin
  986.   { Clear target list box }
  987.   ListBox2.Clear;
  988.   for Counter_1 := 0 to TheMBMessagesList.Count - 1 do
  989.   begin
  990.     TheEMMRecord :=
  991.      PEMailMessageRecord( TheMBMessagesList.Items[ Counter_1 ] );
  992.     TempString := '    [' + IntToStr( Counter_1 + 1 ) + '] ' +
  993.      TheEMMRecord^.MRMessageSubject;
  994.     if TheEMMRecord^.MRRead then TempString[ 2 ] := 'R';
  995.     if TheEMMRecord^.MRSent then TempString[ 2 ] := 'S';
  996.     if TheEMMRecord^.MRMessageSender = 'DELETE ME' then TempString[ 3 ] := 'T';
  997.     ListBox2.Items.Add( TempString );
  998.   end;
  999. end;
  1000.  
  1001. { This procedure swaps in the list of subscribed newsgroups to LB1 }
  1002. { and calls another procedure to populate LB2 with any available   }
  1003. { articles for the newsgroup.                                      }
  1004. procedure TCCINetCCForm.SetupEMailListboxes;
  1005. var Counter_1   : Integer;
  1006.     TempString  : String;
  1007.     TheMBRecord : PEMailMailboxRecord;
  1008. begin
  1009.   ListBox1.Clear;
  1010.   ListBox1.Tag := 6;
  1011.   ListBox2.Tag := 6;
  1012.   Label4.Caption := 'Mailboxes';
  1013.   Label5.Caption := 'Messages';
  1014.   if TheEMailMailboxList.Count = 0 then
  1015.   begin
  1016.     ListBox2.Clear;
  1017.     exit;
  1018.   end;
  1019.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  1020.   begin
  1021.     TheMBRecord := PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] );
  1022.     TempString := TheMBRecord^.MBName;
  1023.     if TheMBRecord^.MBUnSentTotal > 0 then TempString := TempString + ' {' +
  1024.      IntToStr( TheMBRecord^.MBUnSentTotal ) + ' Queued}' else
  1025.      if TheMBRecord^.MBUnReadTotal > 0 then TempString := TempString +
  1026.        ' {' + IntToStr( TheMBRecord^.MBUnReadTotal ) + ' New}';
  1027.     TempString := TempString + '{' + IntToStr( TheMBRecord^.MBTotal ) + ' Stored}';
  1028.     ListBox1.Items.Add( TempString );
  1029.   end;
  1030.   TheMBRecord := PEMailMailboxRecord( TheEMailMailboxList.Items[ 0 ] );
  1031.   TheMBMessagesList := TList( TheMBRecord^.MBLTag );
  1032.   PopulateLB2WithMessageHeaders;
  1033.   Label1.Caption := 'MailBox:';
  1034.   Button1.Caption := 'New Mail';
  1035. end;
  1036.  
  1037. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  1038. procedure TCCINetCCForm.SetupEMailServersInfoDisplay;
  1039. var Counter_1  : Integer;            { Loop counter        }
  1040. begin
  1041.   { Set tag for POP3SMTP stuff }
  1042.   CCICInfoDlg.Tag := 6; { EMail Tag -- servers }
  1043.   { set up caption of main label }
  1044.   CCICInfoDlg.Label2.Caption := 'EMail Server Sites';
  1045.   { hide outline panel }
  1046.   CCICInfoDlg.Panel6.Top := 200;
  1047.   CCICInfoDlg.panel6.Height := 144;
  1048.   CCICInfoDlg.Panel6.Visible := false;
  1049.   CCICInfoDlg.Panel5.Visible := true;
  1050.   CCICInfoDlg.Panel8.Visible := true;
  1051.   CCICInfoDlg.Panel9.Visible := true;
  1052.   { clear the list box }
  1053.   CCICInfoDlg.ListBox1.Visible := false;
  1054.   CCICInfoDlg.ListBox2.Clear;
  1055.   CCINetCCForm.ComboBox1.Clear;
  1056.   { add profile strings to the list box }
  1057.   for Counter_1 := 0 to TheEMailServerList.Count - 1 do
  1058.   begin
  1059.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  1060.      TheEMailServerList.Items[ Counter_1 ] )^.CProfile );
  1061.     CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  1062.      TheEMailServerList.Items[ Counter_1 ] )^.CProfile );
  1063.   end;
  1064.   { Set up caption of special button }
  1065.   CCICInfoDlg.Button1.Visible := false;
  1066.   { Start with top record }
  1067.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  1068.   CCINetCCForm.ComboBox1.ItemIndex := 0;
  1069.   { put in data from top record and reset captions }
  1070.   with PConnectionsRecord( TheEMailServerList.Items[ 0 ] )^ do
  1071.   begin
  1072.     with CCICInfoDlg do
  1073.     begin
  1074.       Edit1.Text := CProfile;
  1075.       Panel2.Caption := '            Name:';
  1076.       Edit2.Text := CIPAddress;
  1077.       Panel3.Caption := '     IP Address:';
  1078.       Edit3.Text := CUserName;
  1079.       Panel5.Caption := '    User Name:';
  1080.       CurrentEMRealPWString := CPassword;
  1081.       case EMPasswordControlVector of
  1082.         1 : Edit4.Text := CPassword;
  1083.         2 : Edit4.Text := '**********';
  1084.       end;
  1085.       Panel8.Caption := '      Password:';
  1086.       Edit5.Text := CStartDir;
  1087.       Panel9.Caption := '    EMail Address:';
  1088.     end;
  1089.   end;
  1090. end;
  1091.  
  1092. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  1093. procedure TCCINetCCForm.SetupEMailMailboxInfoDisplay;
  1094. var Counter_1      : Integer;
  1095.     TheWorkingList : TList;
  1096. begin
  1097.   { Set tag for POP3SMTP stuff }
  1098.   CCICInfoDlg.Tag := 7; { EMail Tag -- mailboxes }
  1099.   { set up caption of main label }
  1100.   CCICInfoDlg.Label2.Caption := 'Mailboxes';
  1101.   { hide outline panel }
  1102.   CCICInfoDlg.Panel6.Visible := true;
  1103.   CCICInfoDlg.Panel6.Top := 40;
  1104.   CCICInfoDlg.Panel6.Height := 304;
  1105.   CCICInfoDlg.Label1.Caption := 'Saved Messages';
  1106.   CCICInfoDlg.Panel3.Visible := false;
  1107.   CCICInfoDlg.Panel5.Visible := false;
  1108.   CCICInfoDlg.Panel8.Visible := false;
  1109.   CCICInfoDlg.Panel9.Visible := false;
  1110.   { clear the list box }
  1111.   CCICInfoDlg.ListBox1.Visible := true;
  1112.   CCICInfoDlg.ListBox1.MultiSelect := true;
  1113.   CCICInfoDlg.ListBox1.ExtendedSelect := true;
  1114.   CCICInfoDlg.ListBox2.Clear;
  1115.   CCICInfoDlg.ListBox1.Clear;
  1116.   { add profile strings to the list box }
  1117.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  1118.   begin
  1119.     CCICInfoDlg.ListBox2.Items.Add( PEMailMailboxRecord(
  1120.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBName );
  1121.   end;
  1122.   { Set up caption of special button }
  1123.   CCICInfoDlg.Button1.Visible := true;
  1124.   CCICInfoDlg.Button1.Caption := 'XFer on Click';
  1125.   { Start with top record }
  1126.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  1127.   { put in data from top record and reset captions }
  1128.   with PEMailMailboxRecord( TheEMailMailboxList.Items[ 0 ] )^ do
  1129.   begin
  1130.     with CCICInfoDlg do
  1131.     begin
  1132.       Edit1.Text := MBName;
  1133.       Panel2.Caption := 'MB Name:';
  1134.       TheWorkingList := TList( MBLTag );
  1135.       if TheWorkingList.Count > 0 then
  1136.       begin
  1137.         ListBox1.Clear;
  1138.         for Counter_1 := 0 to TheWorkingList.Count - 1 do
  1139.         begin
  1140.           ListBox1.Items.Add( PEMailMessageRecord(
  1141.            TheWorkingList.Items[ Counter_1 ] )^.MRMessageSubject );
  1142.         end;
  1143.         Listbox1.ItemIndex := 0;
  1144.       end;
  1145.     end;
  1146.   end;
  1147. end;
  1148.  
  1149. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  1150. procedure TCCINetCCForm.SetupEMailCorrespondentsInfoDisplay;
  1151. var Counter_1  : Integer;            { Loop counter        }
  1152. begin
  1153.   { Set tag for POP3SMTP stuff }
  1154.   CCICInfoDlg.Tag := 8; { EMail Tag -- correspondents }
  1155.   { set up caption of main label }
  1156.   CCICInfoDlg.Label2.Caption := 'Correspondents';
  1157.   { hide outline panel }
  1158.   CCICInfoDlg.Panel3.Visible := true;
  1159.   CCICInfoDlg.Panel6.Visible := false;
  1160.   CCICInfoDlg.Panel5.Visible := false;
  1161.   CCICInfoDlg.Panel8.Visible := false;
  1162.   CCICInfoDlg.Panel9.Visible := false;
  1163.   CCICInfoDlg.ListBox1.Visible := false;
  1164.   { clear the list box }
  1165.   CCICInfoDlg.ListBox2.Clear;
  1166.   { add profile strings to the list box }
  1167.   for Counter_1 := 0 to TheCorrespondentsList.Count - 1 do
  1168.   begin
  1169.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  1170.      TheCorrespondentsList.Items[ Counter_1 ] )^.CProfile );
  1171.   end;
  1172.   { Set up caption of special button }
  1173.   CCICInfoDlg.Button1.Visible := false;
  1174.   { Start with top record }
  1175.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  1176.   { put in data from top record and reset captions }
  1177.   with PConnectionsRecord( TheCorrespondentsList.Items[ 0 ] )^ do
  1178.   begin
  1179.     with CCICInfoDlg do
  1180.     begin
  1181.       Edit1.Text := CProfile;
  1182.       Panel2.Caption := '            Name:';
  1183.       Edit2.Text := CIPAddress;
  1184.       Panel3.Caption := 'EMail Address:';
  1185.     end;
  1186.   end;
  1187. end;
  1188.  
  1189. procedure TCCINetCCForm.EnablePOP3SMTPMenus;
  1190. begin
  1191.   Button1.Caption := 'New Mail';
  1192.   CheckMail1.Enabled := true;
  1193.   CreateNewMessage1.Enabled := true;
  1194.   ReplyToCurrentMessage1.Enabled := true;
  1195.   SendCurrentMessage1.Enabled := true;
  1196.   SendQueue1.Enabled := true;
  1197.   MailServers1.Enabled := true;
  1198.   MailBoxes1.Enabled := true;
  1199.   Correspondents1.Enabled := true;
  1200.   TrashMarkedMessages1.Enabled := true;
  1201.   EmptyTrash1.Enabled := true;
  1202. end;
  1203.  
  1204. procedure TCCINetCCForm.DisablePOP3SMTPMenus;
  1205. begin
  1206.   CheckMail1.Enabled := False;
  1207.   CreateNewMessage1.Enabled := False;
  1208.   ReplyToCurrentMessage1.Enabled := False;
  1209.   SendCurrentMessage1.Enabled := False;
  1210.   SendQueue1.Enabled := False;
  1211.   MailServers1.Enabled := False;
  1212.   MailBoxes1.Enabled := False;
  1213.   Correspondents1.Enabled := False;
  1214.   TrashMarkedMessages1.Enabled := False;
  1215.   EmptyTrash1.Enabled := False;
  1216.   EMail1.Enabled := true;
  1217.   FTP1.Enabled := true;
  1218.   UseNetNws1.Enabled := true;
  1219.   IPAddress1.Enabled := true;
  1220.   EMail2.Enabled := false;
  1221. end;
  1222.  
  1223. { This is the FTP component constructor; it creates 2 sockets }
  1224. constructor TFTPComponent.Create( AOwner : TComponent );
  1225. begin
  1226.   { do inherited create }
  1227.   inherited Create( AOwner );
  1228.   { Create sockets, put in their parents, and error procs }
  1229.   Socket1 := TCCSocket.Create( Self );
  1230.   Socket1.Parent := Self;
  1231.   Socket1.OnErrorOccurred := FTPSocketsErrorOccurred;
  1232.   Socket2 := TCCSocket.Create( Self );
  1233.   Socket2.Parent := Self;
  1234.   Socket2.OnErrorOccurred := FTPSocketsErrorOccurred;
  1235.   { Set up booleans }
  1236.   Connection_Established := false;
  1237.   FTPCommandInProgress := false;
  1238. end;
  1239.  
  1240. { This is the FTP component destructor; it frees 2 sockets }
  1241. destructor TFTPComponent.Destroy;
  1242. begin
  1243.   { Free the sockets }
  1244.   Socket1.Free;
  1245.   Socket2.Free;
  1246.   { and call inherited }
  1247.   inherited Destroy;
  1248. end;
  1249.  
  1250. function TFTPComponent.GetShortPathname( TheString : String ) : String;
  1251. var HoldingString : String;
  1252. begin
  1253.   HoldingString := Copy( TheString , 1 , 3 );
  1254.   HoldingString := HoldingString + '..\' + ExtractFileName( TheString );
  1255.   Result := HoldingString;
  1256. end;
  1257.  
  1258. function TFTPComponent.StripBrackets( TheString : String ) : String;
  1259. var HoldingString : String;
  1260.     HoldingPosition : Integer;
  1261. begin
  1262.   HoldingPosition := Pos( '[' , TheString );
  1263.   if HoldingPosition = 0 then
  1264.   begin
  1265.     Result := TheString;
  1266.     exit;
  1267.   end
  1268.   else
  1269.   begin
  1270.     HoldingString := Copy( TheString , HoldingPosition + 1 , 255 );
  1271.     HoldingPosition := Pos( ']' , HoldingString );
  1272.     if HoldingPosition = 0 then
  1273.     begin
  1274.       Result := HoldingString;
  1275.       exit;
  1276.     end
  1277.     else
  1278.     begin
  1279.       HoldingString := Copy( HoldingString , 1 , HoldingPosition - 1 );
  1280.       Result := HoldingString;
  1281.       exit;
  1282.     end;
  1283.   end;
  1284. end;
  1285.  
  1286. { This function takes a UNIX filespec and turns it into a Win16 filename }
  1287. function TFTPComponent.GetWin16FileName( InputName : String ) : String;
  1288. var WorkingString ,
  1289.     HoldingString   : String; { Holding string }
  1290. begin
  1291.   WorkingString := ExtractFileExt( InputName );
  1292.   if WorkingString = '' then
  1293.   begin
  1294.     if Length( InputName ) > 8 then
  1295.      WorkingString := Copy( InputName , 1 , 8 ) else
  1296.       WorkingString := InputName;
  1297.   end
  1298.   else
  1299.   begin
  1300.     if Length( WorkingString ) > 4 then
  1301.      WorkingString := Copy( WorkingString , 1 , 4 );
  1302.     HoldingString :=
  1303.      Copy( InputName , 1 , Pos( WorkingString , InputName ) - 1 );
  1304.     if Length( HoldingString ) > 8 then
  1305.      HoldingString := Copy( HoldingString , 1 , 8 );
  1306.     if HoldingString = '' then
  1307.     begin
  1308.       { Dot file }
  1309.       HoldingString := Copy( InputName , 2 , 255 ) + '.TXT';
  1310.       WorkingString := HoldingString;
  1311.     end
  1312.     else WorkingString := HoldingString + WorkingString;
  1313.   end;
  1314.   Result := WorkingString;
  1315. end;
  1316.  
  1317. { This sends a local file in binary mode to the remote server }
  1318. procedure TFTPComponent.SendBinaryLocalFile( LocalName : String );
  1319. var TheReturnString : String;  { Internal string holder }
  1320.     TheResult       : Integer; { Internal int holder    }
  1321.     Through         : Boolean;
  1322.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1323.     OutputFileHandle : Integer;
  1324.     TotalBytesSent ,
  1325.     BytesRead ,
  1326.     FileToSendSize    : Longint;
  1327.     CopyBuffer       : array[ 0 .. 255 ] of char absolute TheReturnString;
  1328. begin
  1329.   LocalName := ExpandFileName( LocalName );
  1330.   StrPCopy( FileNamePChar , LocalName );
  1331.   OutputFileHandle := _lopen( FileNamePChar , 0 );
  1332.   if OutputFileHandle = -1 then
  1333.   begin
  1334.     MessageDlg( 'Cannot Open local file ' + LocalName ,
  1335.      mtError , [mbOK] , 0 );
  1336.     exit;
  1337.   end;
  1338.   FileToSendSize := _llseek( OutputFileHandle , 0 , 2 );
  1339.   _llseek( OutputFileHandle , 0 , 0 );
  1340.   TheReturnString :=
  1341.    DoCStyleFormat( 'TYPE I' ,
  1342.     [ nil ] );
  1343.   { Put result in progress and status line }
  1344.   AddProgressText( TheReturnString );
  1345.   ShowProgressText( TheReturnString );
  1346.   { Send Password sequence }
  1347.   TheResult := PerformFTPCommand( 'TYPE I',
  1348.                                   [ nil ] );
  1349.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1350.   begin
  1351.     FTPCommandInProgress := false;
  1352.     exit;
  1353.   end;
  1354.   repeat
  1355.     TheResult := GetFTPServerResponse( TheReturnString );
  1356.     { Put result in progress and status line }
  1357.     AddProgressText( TheReturnString );
  1358.     ShowProgressText( TheReturnString );
  1359.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1360.   FTPCommandInProgress := false;
  1361.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1362.   begin
  1363.     { Do clever C formatting trick }
  1364.     TheReturnString :=
  1365.      DoCStyleFormat( 'FTP File Send Failed!' ,
  1366.       [ nil ] );
  1367.     { Put result in progress and status line }
  1368.     AddProgressText( TheReturnString );
  1369.     ShowProgressErrorText( TheReturnString );
  1370.     { leave }
  1371.     exit;
  1372.   end
  1373.   else
  1374.   begin
  1375.     { Set up socket 2 for listening }
  1376.     Socket2.AsynchMode := False;
  1377.     Socket2.NonAsynchTimeoutValue := 60;
  1378.     { do a listen and send command to server that this is receipt socket }
  1379.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1380.     begin
  1381.       Socket2.CCSockCancelListen;
  1382.       exit;
  1383.     end;
  1384.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1385.     TheReturnString :=
  1386.      DoCStyleFormat( 'STOR %s' ,
  1387.       [ ExtractFileName( LocalName ) ] );
  1388.     { Put result in progress and status line }
  1389.     AddProgressText( TheReturnString );
  1390.     ShowProgressText( TheReturnString );
  1391.     TheResult := PerformFTPCommand( 'STOR %s' , [ ExtractFileName( LocalName ) ] );
  1392.     GetFTPServerResponse( TheReturnString );
  1393.     AddProgressText( TheReturnString );
  1394.     ShowProgressText( TheReturnString );
  1395.     Socket1.NonAsynchTimeoutValue := 30;
  1396.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1397.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1398.     begin
  1399.       TheReturnString :=
  1400.        DoCStyleFormat( 'Could not create remote file!' ,
  1401.         [ nil ] );
  1402.       { Put result in progress and status line }
  1403.       AddProgressText( TheReturnString );
  1404.       ShowProgressErrorText( TheReturnString );
  1405.       Socket2.CCSockCancelListen;
  1406.       exit;
  1407.     end;
  1408.     Socket2.CCSockAccept;
  1409.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1410.     begin
  1411.       TheReturnString :=
  1412.        DoCStyleFormat( 'Could not establish send socket!' ,
  1413.         [ nil ] );
  1414.       { Put result in progress and status line }
  1415.       AddProgressText( TheReturnString );
  1416.       ShowProgressErrorText( TheReturnString );
  1417.       exit;
  1418.     end;
  1419.     Through := false;
  1420.     TotalBytesSent := 0;
  1421.     BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1422.     repeat
  1423.       if BytesRead = 0 then Through := true;
  1424.       if BytesRead > 0 then
  1425.       begin
  1426.         CopyBuffer[ 0 ] := Chr( BytesRead );
  1427.         Socket2.StringData := TheReturnString;
  1428.         TotalBytesSent := TotalBytesSent + BytesRead;
  1429.         UpdateGauge( TotalBytesSent , FileToSendSize );
  1430.         BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1431.         if BytesRead = -1 then
  1432.         begin
  1433.           MessageDlg( 'File Read Error on ' + LocalName , mtError , [mbOK] , 0 );
  1434.           GlobalAbortedFlag := True;
  1435.         end;
  1436.       end;
  1437.       if GlobalAbortedFlag then
  1438.       begin
  1439.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1440.         repeat
  1441.           TheResult := GetFTPServerResponse( TheReturnString );
  1442.           { Put result in progress and status line }
  1443.           AddProgressText( TheReturnString );
  1444.           ShowProgressText( TheReturnString );
  1445.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1446.         exit;
  1447.       end;
  1448.     until Through;
  1449.     FTPCommandInProgress := false;
  1450.     { cancel listening on second socket and close it }
  1451.     Socket2.CCSockCancelListen;
  1452.     Socket2.CCSockClose;
  1453.     TheReturnString := 'Transfer Succeeded' + #13#10;
  1454.     AddProgressText( TheReturnString );
  1455.     ShowProgressText( TheReturnString );
  1456.     FTPCommandInProgress := false;
  1457.     PerformFTPCommand( 'TYPE A',
  1458.                                     [ nil ] );
  1459.     Through := false;
  1460.     repeat
  1461.       GetFTPServerResponse( TheReturnString );
  1462.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1463.        Through := true;
  1464.       { Put result in progress and status line }
  1465.       AddProgressText( TheReturnString );
  1466.       ShowProgressText( TheReturnString );
  1467.     until (( GlobalAbortedFlag ) or Through );
  1468.   end;
  1469.   _lclose( OutputFileHandle );
  1470.   FTPCommandInProgress := false;
  1471. end;
  1472.  
  1473. { This sends a local file in ascii mode to remote server }
  1474. procedure TFTPComponent.SendASCIILocalFile( LocalName : String );
  1475. var TheReturnString : String;  { Internal string holder }
  1476.     TheResult       : Integer; { Internal int holder    }
  1477.     Through         : Boolean;
  1478.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1479.     OutputFileHandle : Integer;
  1480.     TotalBytesSent ,
  1481.     BytesRead ,
  1482.     FileToSendSize    : Longint;
  1483.     CopyBuffer       : array[ 0 .. 255 ] of char absolute TheReturnString;
  1484. begin
  1485.   LocalName := ExpandFileName( LocalName );
  1486.   StrPCopy( FileNamePChar , LocalName );
  1487.   OutputFileHandle := _lopen( FileNamePChar , 0 );
  1488.   if OutputFileHandle = -1 then
  1489.   begin
  1490.     MessageDlg( 'Cannot Open local file ' + LocalName ,
  1491.      mtError , [mbOK] , 0 );
  1492.     exit;
  1493.   end;
  1494.   FileToSendSize := _llseek( OutputFileHandle , 0 , 2 );
  1495.   _llseek( OutputFileHandle , 0 , 0 );
  1496.   TheReturnString :=
  1497.    DoCStyleFormat( 'TYPE A' ,
  1498.     [ nil ] );
  1499.   { Put result in progress and status line }
  1500.   AddProgressText( TheReturnString );
  1501.   ShowProgressText( TheReturnString );
  1502.   { Send Password sequence }
  1503.   TheResult := PerformFTPCommand( 'TYPE A',
  1504.                                   [ nil ] );
  1505.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1506.   begin
  1507.     FTPCommandInProgress := false;
  1508.     exit;
  1509.   end;
  1510.   repeat
  1511.     TheResult := GetFTPServerResponse( TheReturnString );
  1512.     { Put result in progress and status line }
  1513.     AddProgressText( TheReturnString );
  1514.     ShowProgressText( TheReturnString );
  1515.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1516.   FTPCommandInProgress := false;
  1517.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1518.   begin
  1519.     { Do clever C formatting trick }
  1520.     TheReturnString :=
  1521.      DoCStyleFormat( 'FTP File Send Failed!' ,
  1522.       [ nil ] );
  1523.     { Put result in progress and status line }
  1524.     AddProgressText( TheReturnString );
  1525.     ShowProgressErrorText( TheReturnString );
  1526.     { leave }
  1527.     exit;
  1528.   end
  1529.   else
  1530.   begin
  1531.     { Set up socket 2 for listening }
  1532.     Socket2.AsynchMode := False;
  1533.     Socket2.NonAsynchTimeoutValue := 60;
  1534.     { do a listen and send command to server that this is receipt socket }
  1535.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1536.     begin
  1537.       Socket2.CCSockCancelListen;
  1538.       exit;
  1539.     end;
  1540.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1541.     TheReturnString :=
  1542.      DoCStyleFormat( 'STOR %s' ,
  1543.       [ ExtractFileName( LocalName ) ] );
  1544.     { Put result in progress and status line }
  1545.     AddProgressText( TheReturnString );
  1546.     ShowProgressText( TheReturnString );
  1547.     TheResult := PerformFTPCommand( 'STOR %s' , [ ExtractFileName( LocalName )]);
  1548.     GetFTPServerResponse( TheReturnString );
  1549.     AddProgressText( TheReturnString );
  1550.     ShowProgressText( TheReturnString );
  1551.     Socket1.NonAsynchTimeoutValue := 30;
  1552.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1553.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1554.     begin
  1555.       TheReturnString :=
  1556.        DoCStyleFormat( 'Could not create remote file!' ,
  1557.         [ nil ] );
  1558.       { Put result in progress and status line }
  1559.       AddProgressText( TheReturnString );
  1560.       ShowProgressErrorText( TheReturnString );
  1561.       Socket2.CCSockCancelListen;
  1562.       exit;
  1563.     end;
  1564.     Socket2.CCSockAccept;
  1565.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1566.     begin
  1567.       TheReturnString :=
  1568.        DoCStyleFormat( 'Could not establish send socket!' ,
  1569.         [ nil ] );
  1570.       { Put result in progress and status line }
  1571.       AddProgressText( TheReturnString );
  1572.       ShowProgressErrorText( TheReturnString );
  1573.       exit;
  1574.     end;
  1575.     Through := false;
  1576.     TotalBytesSent := 0;
  1577.     BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1578.     repeat
  1579.       if BytesRead = 0 then Through := true;
  1580.       if BytesRead > 0 then
  1581.       begin
  1582.         CopyBuffer[ 0 ] := Chr( BytesRead );
  1583.         Socket2.StringData := TheReturnString;
  1584.         TotalBytesSent := TotalBytesSent + BytesRead;
  1585.         UpdateGauge( TotalBytesSent , FileToSendSize );
  1586.         BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1587.         if BytesRead = -1 then
  1588.         begin
  1589.           MessageDlg( 'File Read Error on ' + LocalName , mtError , [mbOK] , 0 );
  1590.           GlobalAbortedFlag := True;
  1591.         end;
  1592.       end;
  1593.       if GlobalAbortedFlag then
  1594.       begin
  1595.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1596.         repeat
  1597.           TheResult := GetFTPServerResponse( TheReturnString );
  1598.           { Put result in progress and status line }
  1599.           AddProgressText( TheReturnString );
  1600.           ShowProgressText( TheReturnString );
  1601.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1602.         exit;
  1603.       end;
  1604.     until Through;
  1605.     { cancel listening on second socket and close it }
  1606.     Socket2.CCSockCancelListen;
  1607.     Socket2.CCSockClose;
  1608.     TheReturnString := 'Transfer Succeeded' + #13#10;
  1609.     AddProgressText( TheReturnString );
  1610.     ShowProgressText( TheReturnString );
  1611.     FTPCommandInProgress := false;
  1612.     PerformFTPCommand( 'TYPE A', [ nil ] );
  1613.     Through := false;
  1614.     repeat
  1615.       GetFTPServerResponse( TheReturnString );
  1616.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1617.        Through := true;
  1618.       { Put result in progress and status line }
  1619.       AddProgressText( TheReturnString );
  1620.       ShowProgressText( TheReturnString );
  1621.     until (( GlobalAbortedFlag ) or Through );
  1622.   end;
  1623.   _lclose( OutputFileHandle );
  1624.   FTPCommandInProgress := false;
  1625. end;
  1626.  
  1627. { This function strips out the FTP response for bytes to send }
  1628. function TFTPComponent.GetTotalBytesToReceive( TheString : String ) : Longint;
  1629. var
  1630.   LeftPosition ,
  1631.   RightPosition  : integer;
  1632.   TempString     : string;
  1633. begin
  1634.   LeftPosition := Pos( '(' , TheString );
  1635.   TempString := Copy( TheString ,
  1636.                       LeftPosition + 1 , 255 );
  1637.   RightPosition := Pos( ' ' , TempString );
  1638.   if (( LeftPosition = 0 ) or ( RightPosition = 0 )) then
  1639.   begin
  1640.     Result := 0;
  1641.     exit;
  1642.   end;
  1643.   if RightPosition <> 0 then
  1644.     TempString := Copy( TempString , 1 , RightPosition - 1  );
  1645.   try
  1646.     Result := StrToInt( TempString );
  1647.   except
  1648.     on EConvertError do Result := 0;
  1649.   end;
  1650. end;
  1651.  
  1652. procedure TFTPComponent.UpdateGauge( BytesFinished , TotalToHandle : longint );
  1653. begin
  1654.   CCInetCCForm.UpdateGauge( BytesFinished , TotalToHandle );
  1655. end;
  1656.  
  1657. { This sends FTP progress text to the Inet form }
  1658. procedure TFTPComponent.AddProgressText( WhatText : String );
  1659. begin
  1660.   CCInetCCForm.AddProgressText( WhatText );
  1661. end;
  1662.  
  1663. { This sends FTP progress text to the Inet form }
  1664. procedure TFTPComponent.ShowProgressText( WhatText : String );
  1665. begin
  1666.   CCInetCCForm.ShowProgressText( WhatText );
  1667. end;
  1668.  
  1669. { This procedure receives a binary remote file }
  1670. procedure TFTPComponent.ReceiveASCIIRemoteFileToMemo( RemoteName : String );
  1671. var TheReturnString : String;  { Internal string holder }
  1672.     TheResult       : Integer; { Internal int holder    }
  1673.     Through         : Boolean;
  1674.     TotalBytesSent ,
  1675.     FileToGetSize    : Longint;
  1676. begin
  1677.   TheReturnString :=
  1678.    DoCStyleFormat( 'TYPE A' ,
  1679.     [ nil ] );
  1680.   { Put result in progress and status line }
  1681.   AddProgressText( TheReturnString );
  1682.   ShowProgressText( TheReturnString );
  1683.   { Send Password sequence }
  1684.   FTPCommandInProgress := false;
  1685.   TheResult := PerformFTPCommand( 'TYPE A',
  1686.                                   [ nil ] );
  1687.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1688.   begin
  1689.     FTPCommandInProgress := false;
  1690.     exit;
  1691.   end;
  1692.   repeat
  1693.     TheResult := GetFTPServerResponse( TheReturnString );
  1694.     { Put result in progress and status line }
  1695.     AddProgressText( TheReturnString );
  1696.     ShowProgressText( TheReturnString );
  1697.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1698.   FTPCommandInProgress := false;
  1699.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1700.   begin
  1701.     { Do clever C formatting trick }
  1702.     TheReturnString :=
  1703.      DoCStyleFormat( 'FTP File Receive Failed!' ,
  1704.       [ nil ] );
  1705.     { Put result in progress and status line }
  1706.     AddProgressText( TheReturnString );
  1707.     ShowProgressErrorText( TheReturnString );
  1708.     { leave }
  1709.     exit;
  1710.   end
  1711.   else
  1712.   begin
  1713.     { Set up socket 2 for listening }
  1714.     Socket2.AsynchMode := False;
  1715.     Socket2.NonAsynchTimeoutValue := 60;
  1716.     { do a listen and send command to server that this is receipt socket }
  1717.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1718.     begin
  1719.       Socket2.CCSockCancelListen;
  1720.       exit;
  1721.     end;
  1722.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1723.     TheReturnString :=
  1724.      DoCStyleFormat( 'RETR %s' ,
  1725.       [ RemoteName ] );
  1726.     { Put result in progress and status line }
  1727.     AddProgressText( TheReturnString );
  1728.     ShowProgressText( TheReturnString );
  1729.     TheResult := PerformFTPCommand( 'RETR %s' , [RemoteName] );
  1730.     GetFTPServerResponse( TheReturnString );
  1731.     AddProgressText( TheReturnString );
  1732.     ShowProgressText( TheReturnString );
  1733.     FileToGetSize := GetTotalBytesToReceive( TheReturnString );
  1734.     Socket1.NonAsynchTimeoutValue := 30;
  1735.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1736.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1737.     begin
  1738.       TheReturnString :=
  1739.        DoCStyleFormat( 'Could not obtain remote file!' ,
  1740.         [ nil ] );
  1741.       { Put result in progress and status line }
  1742.       AddProgressText( TheReturnString );
  1743.       ShowProgressErrorText( TheReturnString );
  1744.       Socket2.CCSockCancelListen;
  1745.       exit;
  1746.     end;
  1747.     Socket2.CCSockAccept;
  1748.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1749.     begin
  1750.       TheReturnString :=
  1751.        DoCStyleFormat( 'Could not establish receive socket!' ,
  1752.         [ nil ] );
  1753.       { Put result in progress and status line }
  1754.       AddProgressText( TheReturnString );
  1755.       ShowProgressErrorText( TheReturnString );
  1756.       exit;
  1757.     end;
  1758.     Through := false;
  1759.     TotalBytesSent := 0;
  1760.     repeat
  1761.       TheReturnString := Socket2.StringData;
  1762.       if Length( TheReturnString ) = 0 then Through := true;
  1763.       if Length( TheReturnString ) > 0 then
  1764.       begin
  1765.         TotalBytesSent := TotalBytesSent + Length( TheReturnString );
  1766.         UpdateGauge( TotalBytesSent , FileToGetSize );
  1767.         { Put result in progress and status line }
  1768.         AddProgressText( TheReturnString );
  1769.         ShowProgressText( TheReturnString );
  1770.       end;
  1771.       if GlobalAbortedFlag then
  1772.       begin
  1773.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1774.         repeat
  1775.           TheResult := GetFTPServerResponse( TheReturnString );
  1776.           { Put result in progress and status line }
  1777.           AddProgressText( TheReturnString );
  1778.           ShowProgressText( TheReturnString );
  1779.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1780.         exit;
  1781.       end;
  1782.     until Through;
  1783.     { cancel listening on second socket and close it }
  1784.     Socket2.CCSockCancelListen;
  1785.     Socket2.CCSockClose;
  1786.     FTPCommandInProgress := false;
  1787.     PerformFTPCommand( 'TYPE A', [ nil ] );
  1788.     Through := false;
  1789.     repeat
  1790.       GetFTPServerResponse( TheReturnString );
  1791.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1792.        Through := true;
  1793.       { Put result in progress and status line }
  1794.       AddProgressText( TheReturnString );
  1795.       ShowProgressText( TheReturnString );
  1796.     until (( GlobalAbortedFlag ) or Through );
  1797.   end;
  1798.   FTPCommandInProgress := false;
  1799. end;
  1800.  
  1801. { This procedure receives a binary remote file }
  1802. procedure TFTPComponent.ReceiveASCIIRemoteFile( RemoteName , LocalName : String );
  1803. var TheReturnString : String;  { Internal string holder }
  1804.     TheResult       : Integer; { Internal int holder    }
  1805.     Through         : Boolean;
  1806.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1807.     OutputFileHandle : Integer;
  1808.     TotalBytesSent ,
  1809.     FileToGetSize    : Longint;
  1810.     CopyBuffer       : array[ 0 .. 255 ] of char;
  1811. begin
  1812.   LocalName := ExpandFileName( LocalName );
  1813.   StrPCopy( FileNamePChar , LocalName );
  1814.   OutputFileHandle := _lcreat( FileNamePChar , 0 );
  1815.   if OutputFileHandle = -1 then
  1816.   begin
  1817.     MessageDlg( 'Cannot Create local file ' + LocalName ,
  1818.      mtError , [mbOK] , 0 );
  1819.     exit;
  1820.   end;
  1821.   TheReturnString :=
  1822.    DoCStyleFormat( 'TYPE A' ,
  1823.     [ nil ] );
  1824.   { Put result in progress and status line }
  1825.   AddProgressText( TheReturnString );
  1826.   ShowProgressText( TheReturnString );
  1827.   { Send Password sequence }
  1828.   TheResult := PerformFTPCommand( 'TYPE A',
  1829.                                   [ nil ] );
  1830.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1831.   begin
  1832.     FTPCommandInProgress := false;
  1833.     exit;
  1834.   end;
  1835.   repeat
  1836.     TheResult := GetFTPServerResponse( TheReturnString );
  1837.     { Put result in progress and status line }
  1838.     AddProgressText( TheReturnString );
  1839.     ShowProgressText( TheReturnString );
  1840.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1841.   FTPCommandInProgress := false;
  1842.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1843.   begin
  1844.     { Do clever C formatting trick }
  1845.     TheReturnString :=
  1846.      DoCStyleFormat( 'FTP File Receive Failed!' ,
  1847.       [ nil ] );
  1848.     { Put result in progress and status line }
  1849.     AddProgressText( TheReturnString );
  1850.     ShowProgressErrorText( TheReturnString );
  1851.     { leave }
  1852.     exit;
  1853.   end
  1854.   else
  1855.   begin
  1856.     { Set up socket 2 for listening }
  1857.     Socket2.AsynchMode := False;
  1858.     Socket2.NonAsynchTimeoutValue := 60;
  1859.     { do a listen and send command to server that this is receipt socket }
  1860.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1861.     begin
  1862.       Socket2.CCSockCancelListen;
  1863.       exit;
  1864.     end;
  1865.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1866.     TheReturnString :=
  1867.      DoCStyleFormat( 'RETR %s' ,
  1868.       [ RemoteName ] );
  1869.     { Put result in progress and status line }
  1870.     AddProgressText( TheReturnString );
  1871.     ShowProgressText( TheReturnString );
  1872.     TheResult := PerformFTPCommand( 'RETR %s' , [RemoteName] );
  1873.     GetFTPServerResponse( TheReturnString );
  1874.     AddProgressText( TheReturnString );
  1875.     ShowProgressText( TheReturnString );
  1876.     FileToGetSize := GetTotalBytesToReceive( TheReturnString );
  1877.     Socket1.NonAsynchTimeoutValue := 30;
  1878.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1879.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1880.     begin
  1881.       TheReturnString :=
  1882.        DoCStyleFormat( 'Could not obtain remote file!' ,
  1883.         [ nil ] );
  1884.       { Put result in progress and status line }
  1885.       AddProgressText( TheReturnString );
  1886.       ShowProgressErrorText( TheReturnString );
  1887.       Socket2.CCSockCancelListen;
  1888.       exit;
  1889.     end;
  1890.     Socket2.CCSockAccept;
  1891.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1892.     begin
  1893.       TheReturnString :=
  1894.        DoCStyleFormat( 'Could not establish receive socket!' ,
  1895.         [ nil ] );
  1896.       { Put result in progress and status line }
  1897.       AddProgressText( TheReturnString );
  1898.       ShowProgressErrorText( TheReturnString );
  1899.       exit;
  1900.     end;
  1901.     Through := false;
  1902.     TotalBytesSent := 0;
  1903.     repeat
  1904.       TheReturnString := Socket2.StringData;
  1905.       if Length( TheReturnString ) = 0 then Through := true;
  1906.       if Length( TheReturnString ) > 0 then
  1907.       begin
  1908.         StrPCopy( CopyBuffer , TheReturnString );
  1909.         TotalBytesSent := TotalBytesSent + Length( TheReturnString );
  1910.         UpdateGauge( TotalBytesSent , FileToGetSize );
  1911.         if _lwrite( OutputFileHandle , CopyBuffer , Length( TheReturnString ))
  1912.          = -1 then
  1913.         begin
  1914.           MessageDlg( 'File Write Error on ' + LocalName , mtError , [mbOK] , 0 );
  1915.           GlobalAbortedFlag := True;
  1916.         end;
  1917.       end;
  1918.       if GlobalAbortedFlag then
  1919.       begin
  1920.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1921.         repeat
  1922.           TheResult := GetFTPServerResponse( TheReturnString );
  1923.           { Put result in progress and status line }
  1924.           AddProgressText( TheReturnString );
  1925.           ShowProgressText( TheReturnString );
  1926.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1927.         exit;
  1928.       end;
  1929.     until Through;
  1930.     { cancel listening on second socket and close it }
  1931.     Socket2.CCSockCancelListen;
  1932.     Socket2.CCSockClose;
  1933.     FTPCommandInProgress := false;
  1934.     PerformFTPCommand( 'TYPE A', [ nil ] );
  1935.     Through := false;
  1936.     repeat
  1937.       GetFTPServerResponse( TheReturnString );
  1938.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1939.        Through := true;
  1940.       { Put result in progress and status line }
  1941.       AddProgressText( TheReturnString );
  1942.       ShowProgressText( TheReturnString );
  1943.     until (( GlobalAbortedFlag ) or Through );
  1944.   end;
  1945.   _lclose( OutputFileHandle );
  1946.   FTPCommandInProgress := false;
  1947. end;
  1948.  
  1949. { This procedure receives a binary remote file }
  1950. procedure TFTPComponent.ReceiveBinaryRemoteFile( RemoteName , LocalName : String );
  1951. var TheReturnString : String;  { Internal string holder }
  1952.     TheResult       : Integer; { Internal int holder    }
  1953.     Through         : Boolean;
  1954.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1955.     OutputFileHandle : Integer;
  1956.     TotalBytesSent ,
  1957.     FileToGetSize    : Longint;
  1958.     CopyBuffer       : array[ 0 .. 255 ] of char;
  1959. begin
  1960.   LocalName := ExpandFileName( LocalName );
  1961.   StrPCopy( FileNamePChar , LocalName );
  1962.   OutputFileHandle := _lcreat( FileNamePChar , 0 );
  1963.   if OutputFileHandle = -1 then
  1964.   begin
  1965.     MessageDlg( 'Cannot Create local file ' + LocalName ,
  1966.      mtError , [mbOK] , 0 );
  1967.     exit;
  1968.   end;
  1969.   TheReturnString :=
  1970.    DoCStyleFormat( 'TYPE I' ,
  1971.     [ nil ] );
  1972.   { Put result in progress and status line }
  1973.   AddProgressText( TheReturnString );
  1974.   ShowProgressText( TheReturnString );
  1975.   { Send Password sequence }
  1976.   TheResult := PerformFTPCommand( 'TYPE I',
  1977.                                   [ nil ] );
  1978.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1979.   begin
  1980.     FTPCommandInProgress := false;
  1981.     exit;
  1982.   end;
  1983.   repeat
  1984.     TheResult := GetFTPServerResponse( TheReturnString );
  1985.     { Put result in progress and status line }
  1986.     AddProgressText( TheReturnString );
  1987.     ShowProgressText( TheReturnString );
  1988.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1989.   FTPCommandInProgress := false;
  1990.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1991.   begin
  1992.     { Do clever C formatting trick }
  1993.     TheReturnString :=
  1994.      DoCStyleFormat( 'FTP File Receive Failed!' ,
  1995.       [ nil ] );
  1996.     { Put result in progress and status line }
  1997.     AddProgressText( TheReturnString );
  1998.     ShowProgressErrorText( TheReturnString );
  1999.     { leave }
  2000.     exit;
  2001.   end
  2002.   else
  2003.   begin
  2004.     { Set up socket 2 for listening }
  2005.     Socket2.AsynchMode := False;
  2006.     Socket2.NonAsynchTimeoutValue := 60;
  2007.     { do a listen and send command to server that this is receipt socket }
  2008.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  2009.     begin
  2010.       Socket2.CCSockCancelListen;
  2011.       exit;
  2012.     end;
  2013.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  2014.     TheReturnString :=
  2015.      DoCStyleFormat( 'RETR %s' ,
  2016.       [ RemoteName ] );
  2017.     { Put result in progress and status line }
  2018.     AddProgressText( TheReturnString );
  2019.     ShowProgressText( TheReturnString );
  2020.     TheResult := PerformFTPCommand( 'RETR %s' , [RemoteName] );
  2021.     GetFTPServerResponse( TheReturnString );
  2022.     AddProgressText( TheReturnString );
  2023.     ShowProgressText( TheReturnString );
  2024.     FileToGetSize := GetTotalBytesToReceive( TheReturnString );
  2025.     Socket1.NonAsynchTimeoutValue := 30;
  2026.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  2027.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  2028.     begin
  2029.       TheReturnString :=
  2030.        DoCStyleFormat( 'Could not obtain remote file!' ,
  2031.         [ nil ] );
  2032.       { Put result in progress and status line }
  2033.       AddProgressText( TheReturnString );
  2034.       ShowProgressErrorText( TheReturnString );
  2035.       Socket2.CCSockCancelListen;
  2036.       exit;
  2037.     end;
  2038.     Socket2.CCSockAccept;
  2039.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  2040.     begin
  2041.       TheReturnString :=
  2042.        DoCStyleFormat( 'Could not establish receive socket!' ,
  2043.         [ nil ] );
  2044.       { Put result in progress and status line }
  2045.       AddProgressText( TheReturnString );
  2046.       ShowProgressErrorText( TheReturnString );
  2047.       exit;
  2048.     end;
  2049.     Through := false;
  2050.     TotalBytesSent := 0;
  2051.     repeat
  2052.       TheReturnString := Socket2.StringData;
  2053.       if Length( TheReturnString ) = 0 then Through := true;
  2054.       if Length( TheReturnString ) > 0 then
  2055.       begin
  2056.         StrPCopy( CopyBuffer , TheReturnString );
  2057.         TotalBytesSent := TotalBytesSent + Length( TheReturnString );
  2058.         UpdateGauge( TotalBytesSent , FileToGetSize );
  2059.         if _lwrite( OutputFileHandle , CopyBuffer , Length( TheReturnString ))
  2060.          = -1 then
  2061.         begin
  2062.           MessageDlg( 'File Write Error on ' + LocalName , mtError , [mbOK] , 0 );
  2063.           GlobalAbortedFlag := True;
  2064.         end;
  2065.       end;
  2066.       if GlobalAbortedFlag then
  2067.       begin
  2068.         Socket1.OutOfBand := 'ABOR'+#13#10;
  2069.         repeat
  2070.           TheResult := GetFTPServerResponse( TheReturnString );
  2071.           { Put result in progress and status line }
  2072.           AddProgressText( TheReturnString );
  2073.           ShowProgressText( TheReturnString );
  2074.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2075.         exit;
  2076.       end;
  2077.     until Through;
  2078.     { cancel listening on second socket and close it }
  2079.     Socket2.CCSockCancelListen;
  2080.     Socket2.CCSockClose;
  2081.     FTPCommandInProgress := false;
  2082.     PerformFTPCommand( 'TYPE A', [ nil ] );
  2083.     Through := false;
  2084.     repeat
  2085.       GetFTPServerResponse( TheReturnString );
  2086.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  2087.        Through := true;
  2088.       { Put result in progress and status line }
  2089.       AddProgressText( TheReturnString );
  2090.       ShowProgressText( TheReturnString );
  2091.     until (( GlobalAbortedFlag ) or Through );
  2092.   end;
  2093.   _lclose( OutputFileHandle );
  2094.   FTPCommandInProgress := false;
  2095. end;
  2096.  
  2097. { This sends FTP progress text to the Inet form }
  2098. procedure TFTPComponent.ShowProgressErrorText( WhatText : String );
  2099. begin
  2100.   CCInetCCForm.ShowProgressErrorText( WhatText );
  2101. end;
  2102.  
  2103. { This is a core function! It performs an FTP command and if no timeout }
  2104. { return a preliminary ok.                                              }
  2105. function TFTPComponent.PerformFTPCommand(
  2106.                  TheCommand        : string;
  2107.            const TheArguments      : array of const ) : Integer;
  2108. var TheBuffer : string; { Text buffer }
  2109. begin
  2110.   { If command in progress send back -1 error }
  2111.   if FTPCommandInProgress then
  2112.   begin
  2113.     Result := -1;
  2114.     exit;
  2115.   end;
  2116.   { Set status variable }
  2117.   FTPCommandInProgress := True;
  2118.   { Set global error code }
  2119.   GlobalErrorCode := 0;
  2120.   { Format output string }
  2121.   TheBuffer := Format( TheCommand , TheArguments );
  2122.   { Preset failure code }
  2123.   Result := TCPIP_STATUS_FATAL_ERROR;
  2124.   { If invalid socket or no connection abort }
  2125.   if ( Socket1.TheSocket = INVALID_SOCKET ) or not Connection_Established then
  2126.    exit;
  2127.   { Send the buffer plus EOL chars }
  2128.   Socket1.StringData := TheBuffer + #13#10;
  2129.   { if abort due to timeout or other error exit }
  2130.   if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then exit;
  2131.   { Otherwise return preliminary code }
  2132.   Result := TCPIP_STATUS_PRELIMINARY;
  2133. end;
  2134.  
  2135. { This function gets up to 255 chars of data plus a return code from FTP serv }
  2136. function TFTPComponent.GetFTPServerResponse(
  2137.           var ResponseString : String ) : integer;
  2138. var
  2139.   { Buffer string for response line }
  2140.   TheBuffer     : string;
  2141.   { Pointer to the response string }
  2142.   BufferPointer : array[0..255] of char absolute TheBuffer;
  2143.   { Character to check for response code }
  2144.   ResponseChar   : char;
  2145.   { Pointers into returned string }
  2146.   TheIndex ,
  2147.   TheLength     : integer;
  2148.   { Control variable }
  2149.   LeftoversInPan ,
  2150.   Finished      : Boolean;
  2151. begin
  2152.   { Preset fatal error }
  2153.   Result := TCPIP_STATUS_FATAL_ERROR;
  2154.   { Start loop control }
  2155.   LeftoversInPan := false;
  2156.   Finished := false;
  2157.   repeat
  2158.     { Do a peek }
  2159.     TheBuffer := Socket1.PeekData;
  2160.     { If timeout or other error exit }
  2161.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then exit;
  2162.     { Find end of line character }
  2163.     TheIndex := Pos( #10 , TheBuffer );
  2164.     if TheIndex = 0 then
  2165.     begin
  2166.       TheIndex := Pos( #13 , TheBuffer );
  2167.       if TheIndex = 0 then
  2168.       begin
  2169.         TheIndex := Pos( #0 , TheBuffer );
  2170.         if TheIndex = 0 then
  2171.         begin
  2172.           TheIndex := Length( TheBuffer );
  2173.           LeftoversInPan := True;
  2174.           LeftoverText := LeftoverText + TheBuffer;
  2175.           LeftoversOnTable := false;
  2176.         end;
  2177.       end;
  2178.     end;
  2179.     { If an end of line then process the line }
  2180.     if TheIndex > 0 then
  2181.     begin
  2182.       { Get length of string }
  2183.       TheLength := TheIndex;
  2184.       { Receive actual data }
  2185.       Socket1.CCSockReceive( Socket1.TheSocket   ,
  2186.                              @BufferPointer[ 1 ] ,
  2187.                              TheLength              );
  2188.       { Abort if timeout or error }
  2189.       if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then exit;
  2190.       { Put in the length byte }
  2191.       BufferPointer[ 0 ] := Chr( TheLength );
  2192.       if LeftOversOnTable then
  2193.       begin
  2194.         LeftOversOnTable := false;
  2195.         ResponseString := LeftoverText + TheBuffer;
  2196.         TheBuffer := ResponseString;
  2197.         LeftoverText := '';
  2198.       end;
  2199.       if LeftoversInPan then
  2200.       begin
  2201.         LeftoversInPan := false;
  2202.         LeftoversOnTable := true;
  2203.       end;
  2204.       { If not a continuation line }
  2205.       if TheBuffer[ 4 ] <> '-' then
  2206.       begin
  2207.         { Get first number character }
  2208.         ResponseChar := TheBuffer[ 1 ];
  2209.         { Get the value of the number from 1 to 5 }
  2210.         if (( ResponseChar >= '1' ) and ( ResponseChar <= '5' )) then
  2211.         begin
  2212.           Finished := true;
  2213.           Result := Ord( ResponseChar ) - 48;
  2214.         end;
  2215.       end
  2216.       else
  2217.       begin
  2218.         { otherwise return preliminary result }
  2219.         Finished := true;
  2220.         Result := TCPIP_STATUS_PRELIMINARY;
  2221.       end;
  2222.     end
  2223.     else
  2224.     begin
  2225.     end;
  2226.   until ( Finished and ( not LeftoversOnTable ));
  2227.   { Return buffer as response string }
  2228.   ResponseString := TheBuffer;
  2229. end;
  2230.  
  2231. { Boilerplate error routine }
  2232. procedure TFTPComponent.FTPSocketsErrorOccurred( Sender     : TObject;
  2233.                                                  ErrorCode  : Integer;
  2234.                                                  TheMessage : String   );
  2235. begin
  2236.   CCInetCCForm.SocketsErrorOccurred( Sender,ErrorCode,TheMessage );
  2237. end;
  2238.  
  2239. { This is the FTP components initial connection routine }
  2240. function TFTPComponent.EstablishConnection(
  2241.           PCRPointer : PConnectionsRecord ) : Boolean;
  2242. var TheReturnString : String;  { Internal string holder }
  2243.     TheResult       : Integer; { Internal int holder    }
  2244. begin
  2245.   { Set default FTP Port value }
  2246.   Socket1.PortName := '21';
  2247.   { Get the ip address from the record }
  2248.   Socket1.IPAddressName := PCRPointer^.CIPAddress;
  2249.   { Set blocking mode }
  2250.   Socket1.AsynchMode := False;
  2251.   { Clear condition variables }
  2252.   GlobalErrorCode := 0;
  2253.   GlobalAbortedFlag := false;
  2254.   { Actually attempt to connect }
  2255.   Socket1.CCSockConnect;
  2256.   { Check if connected }
  2257.   if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 ) or
  2258.       ( Socket1.TheSocket = INVALID_SOCKET )) then
  2259.   begin { Didn't connect; signal error and abort }
  2260.     { Do clever C formatting trick }
  2261.     TheReturnString :=
  2262.      DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2263.       [ PCRPointer^.CIPAddress ] );
  2264.     { Put result in progress and status line }
  2265.     AddProgressText( TheReturnString );
  2266.     ShowProgressErrorText( TheReturnString );
  2267.     { Signal error }
  2268.     Result := False;
  2269.     { leave }
  2270.     exit;
  2271.   end
  2272.   else
  2273.   begin
  2274.     Connection_Established := true;
  2275.     { Signal successful connection }
  2276.     TheReturnString := DoCStyleFormat(
  2277.       'Connected on Local port: %s with IP: %s',
  2278.       [ Socket1.GetSocketPort( Socket1.TheSocket ),
  2279.         Socket1.GetSocketIPAddress( Socket1.TheSocket )]);
  2280.     { Put result in progress and status line }
  2281.     CCINetCCForm.AddProgressText( TheReturnString );
  2282.     CCINetCCForm.ShowProgressText( TheReturnString );
  2283.     TheReturnString := DoCStyleFormat(
  2284.      'Connected to Remote port: %s with IP: %s',
  2285.       [ Socket1.GetSocketPeerPort( Socket1.TheSocket ),
  2286.         Socket1.GetSocketPeerIPAddress( Socket1.TheSocket )]);
  2287.     { Put result in progress and status line }
  2288.     CCINetCCForm.AddProgressText( TheReturnString );
  2289.     CCINetCCForm.ShowProgressText( TheReturnString );
  2290.     TheReturnString := DoCStyleFormat( 'Successfully connected to %s',
  2291.      [ Socket1.IPAddressName ]);
  2292.     { Put result in progress and status line }
  2293.     CCINetCCForm.AddProgressText( TheReturnString );
  2294.     CCINetCCForm.ShowProgressText( TheReturnString );
  2295.     repeat
  2296.       TheResult := GetFTPServerResponse( TheReturnString );
  2297.       { Put result in progress and status line }
  2298.       AddProgressText( TheReturnString );
  2299.       ShowProgressText( TheReturnString );
  2300.     until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2301.     if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2302.     begin
  2303.       { Do clever C formatting trick }
  2304.       TheReturnString :=
  2305.        DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2306.         [ PCRPointer^.CIPAddress ] );
  2307.       { Put result in progress and status line }
  2308.       AddProgressText( TheReturnString );
  2309.       ShowProgressErrorText( TheReturnString );
  2310.       { Signal error }
  2311.       Result := False;
  2312.       { leave }
  2313.       exit;
  2314.     end
  2315.     else Result := true; { Signal no problem }
  2316.   end;
  2317. end;
  2318.  
  2319. { This is the FTP components USER login routine }
  2320. function TFTPComponent.LoginUser(
  2321.           PCRPointer : PConnectionsRecord ) : Boolean;
  2322. var TheReturnString : String;  { Internal string holder }
  2323.     TheResult       : Integer; { Internal int holder    }
  2324. begin
  2325.   TheReturnString :=
  2326.    DoCStyleFormat( 'USER %s' ,
  2327.     [ PCRPointer^.CUserName ] );
  2328.   { Put result in progress and status line }
  2329.   AddProgressText( TheReturnString );
  2330.   ShowProgressText( TheReturnString );
  2331.   { Begin login sequence with user name }
  2332.   TheResult := PerformFTPCommand( 'USER %s',
  2333.                                   [ PCRPointer^.CUserName ] );
  2334.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2335.   begin
  2336.     FTPCommandInProgress := false;
  2337.     Result := false;
  2338.     exit;
  2339.   end;
  2340.   repeat
  2341.     TheResult := GetFTPServerResponse( TheReturnString );
  2342.     { Put result in progress and status line }
  2343.     AddProgressText( TheReturnString );
  2344.     ShowProgressText( TheReturnString );
  2345.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2346.   FTPCommandInProgress := false;
  2347.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_CONTINUING )) then
  2348.   begin
  2349.     { Do clever C formatting trick }
  2350.     TheReturnString :=
  2351.      DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2352.       [ PCRPointer^.CIPAddress ] );
  2353.     { Put result in progress and status line }
  2354.     AddProgressText( TheReturnString );
  2355.     ShowProgressErrorText( TheReturnString );
  2356.     { Signal error }
  2357.     Result := False;
  2358.     { leave }
  2359.     exit;
  2360.   end
  2361.   else Result := true; { Signal no problem }
  2362. end;
  2363.  
  2364. function TFTPComponent.DeleteRemoteDirectory( TheDir : String ) : Boolean;
  2365. var TheReturnString : String;  { Internal string holder }
  2366.     TheResult       : Integer; { Internal int holder    }
  2367. begin
  2368.   TheReturnString := DoCStyleFormat( 'RMD %s' ,
  2369.    [ TheDir ] );
  2370.   { Put result in progress and status line }
  2371.   AddProgressText( TheReturnString );
  2372.   ShowProgressText( TheReturnString );
  2373.   { Send Password sequence }
  2374.   TheResult := PerformFTPCommand( 'RMD %s',
  2375.                                   [ TheDir ] );
  2376.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2377.   begin
  2378.     Result := false;
  2379.     FTPCommandInProgress := false;
  2380.     exit;
  2381.   end;
  2382.   repeat
  2383.     TheResult := GetFTPServerResponse( TheReturnString );
  2384.     { Put result in progress and status line }
  2385.     AddProgressText( TheReturnString );
  2386.     ShowProgressText( TheReturnString );
  2387.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2388.   FTPCommandInProgress := false;
  2389.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2390.   begin
  2391.     { Do clever C formatting trick }
  2392.     TheReturnString :=
  2393.      DoCStyleFormat( 'Delete Directory %s Failed!' ,
  2394.       [ TheDir ] );
  2395.     { Put result in progress and status line }
  2396.     AddProgressText( TheReturnString );
  2397.     ShowProgressErrorText( TheReturnString );
  2398.     { Signal error }
  2399.     Result := False;
  2400.     { leave }
  2401.     exit;
  2402.   end
  2403.   else Result := true; { Signal no problem }
  2404. end;
  2405.  
  2406. function TFTPComponent.CreateRemoteDirectory( TheDir : String ) : Boolean;
  2407. var TheReturnString : String;  { Internal string holder }
  2408.     TheResult       : Integer; { Internal int holder    }
  2409. begin
  2410.   TheReturnString := DoCStyleFormat( 'MKD %s' ,
  2411.     [ TheDir ] );
  2412.   { Put result in progress and status line }
  2413.   AddProgressText( TheReturnString );
  2414.   ShowProgressText( TheReturnString );
  2415.   { Send Password sequence }
  2416.   TheResult := PerformFTPCommand( 'MKD %s',
  2417.                                   [ TheDir ] );
  2418.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2419.   begin
  2420.     Result := false;
  2421.     FTPCommandInProgress := false;
  2422.     exit;
  2423.   end;
  2424.   repeat
  2425.     TheResult := GetFTPServerResponse( TheReturnString );
  2426.     { Put result in progress and status line }
  2427.     AddProgressText( TheReturnString );
  2428.     ShowProgressText( TheReturnString );
  2429.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2430.   FTPCommandInProgress := false;
  2431.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2432.   begin
  2433.     { Do clever C formatting trick }
  2434.     TheReturnString :=
  2435.      DoCStyleFormat( 'Create Directory %s Failed!' ,
  2436.       [ TheDir ] );
  2437.     { Put result in progress and status line }
  2438.     AddProgressText( TheReturnString );
  2439.     ShowProgressErrorText( TheReturnString );
  2440.     { Signal error }
  2441.     Result := False;
  2442.     { leave }
  2443.     exit;
  2444.   end
  2445.   else Result := true; { Signal no problem }
  2446. end;
  2447.  
  2448.  
  2449. function TFTPComponent.DeleteRemoteFile( TheFileName : String ) : Boolean;
  2450. var TheReturnString : String;  { Internal string holder }
  2451.     TheResult       : Integer; { Internal int holder    }
  2452. begin
  2453.   TheReturnString := DoCStyleFormat( 'DELE %s' ,
  2454.     [ TheFileName ] );
  2455.   { Put result in progress and status line }
  2456.   AddProgressText( TheReturnString );
  2457.   ShowProgressText( TheReturnString );
  2458.   { Send Password sequence }
  2459.   TheResult := PerformFTPCommand( 'DELE %s',
  2460.                                   [ TheFileName ] );
  2461.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2462.   begin
  2463.     Result := false;
  2464.     FTPCommandInProgress := false;
  2465.     exit;
  2466.   end;
  2467.   repeat
  2468.     TheResult := GetFTPServerResponse( TheReturnString );
  2469.     { Put result in progress and status line }
  2470.     AddProgressText( TheReturnString );
  2471.     ShowProgressText( TheReturnString );
  2472.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2473.   FTPCommandInProgress := false;
  2474.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2475.   begin
  2476.     { Do clever C formatting trick }
  2477.     TheReturnString :=
  2478.      DoCStyleFormat( 'Delete File %s Failed!' ,
  2479.       [ TheFileName ] );
  2480.     { Put result in progress and status line }
  2481.     AddProgressText( TheReturnString );
  2482.     ShowProgressErrorText( TheReturnString );
  2483.     { Signal error }
  2484.     Result := False;
  2485.     { leave }
  2486.     exit;
  2487.   end
  2488.   else Result := true; { Signal no problem }
  2489. end;
  2490.  
  2491. { This is the FTP components PASSWORD routine }
  2492. function TFTPComponent.SendPassword(
  2493.           PCRPointer : PConnectionsRecord ) : Boolean;
  2494. var TheReturnString : String;  { Internal string holder }
  2495.     TheResult       : Integer; { Internal int holder    }
  2496. begin
  2497.   TheReturnString := 'PASS XXXXXX' + #13#10;
  2498.   { Put result in progress and status line }
  2499.   AddProgressText( TheReturnString );
  2500.   ShowProgressText( TheReturnString );
  2501.   { Send Password sequence }
  2502.   TheResult := PerformFTPCommand( 'PASS %s',
  2503.                                   [ PCRPointer^.CPassword ] );
  2504.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2505.   begin
  2506.     Result := false;
  2507.     FTPCommandInProgress := false;
  2508.     exit;
  2509.   end;
  2510.   repeat
  2511.     TheResult := GetFTPServerResponse( TheReturnString );
  2512.     { Put result in progress and status line }
  2513.     AddProgressText( TheReturnString );
  2514.     ShowProgressText( TheReturnString );
  2515.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2516.   FTPCommandInProgress := false;
  2517.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2518.   begin
  2519.     { Do clever C formatting trick }
  2520.     TheReturnString :=
  2521.      DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2522.       [ PCRPointer^.CIPAddress ] );
  2523.     { Put result in progress and status line }
  2524.     AddProgressText( TheReturnString );
  2525.     ShowProgressErrorText( TheReturnString );
  2526.     { Signal error }
  2527.     Result := False;
  2528.     { leave }
  2529.     exit;
  2530.   end
  2531.   else Result := true; { Signal no problem }
  2532. end;
  2533.  
  2534. { This is the FTP components CWD routine }
  2535. function TFTPComponent.SetRemoteStartupDirectory(
  2536.           PCRPointer : PConnectionsRecord ) : Boolean;
  2537. var TheReturnString : String;  { Internal string holder }
  2538.     TheResult       : Integer; { Internal int holder    }
  2539. begin
  2540.   Result := true;
  2541.   if PCRPointer^.CStartDir <> '' then
  2542.   begin
  2543.     TheReturnString :=
  2544.      DoCStyleFormat( 'CWD %s' ,
  2545.       [ PCRPointer^.CStartDir ] );
  2546.     { Put result in progress and status line }
  2547.     AddProgressText( TheReturnString );
  2548.     ShowProgressText( TheReturnString );
  2549.     { Send Password sequence }
  2550.     TheResult := PerformFTPCommand( 'CWD %s',
  2551.                                     [ PCRPointer^.CStartDir ] );
  2552.     if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2553.     begin
  2554.       Result := false;
  2555.       FTPCommandInProgress := false;
  2556.       exit;
  2557.     end;
  2558.     repeat
  2559.       TheResult := GetFTPServerResponse( TheReturnString );
  2560.       { Put result in progress and status line }
  2561.       AddProgressText( TheReturnString );
  2562.       ShowProgressText( TheReturnString );
  2563.    until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2564.    FTPCommandInProgress := false;
  2565.    if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2566.     begin
  2567.       { Do clever C formatting trick }
  2568.       TheReturnString :=
  2569.        DoCStyleFormat( 'CWD to %s Failed!' ,
  2570.         [ PCRPointer^.CStartDir ] );
  2571.       { Put result in progress and status line }
  2572.       AddProgressText( TheReturnString );
  2573.       ShowProgressErrorText( TheReturnString );
  2574.       { Signal error }
  2575.       Result := False;
  2576.       { leave }
  2577.       exit;
  2578.     end
  2579.     else Result := true; { Signal no problem }
  2580.   end;
  2581. end;
  2582.  
  2583. { This is the FTP components CWD routine }
  2584. function TFTPComponent.SetRemoteDirectory( TheDir : String ) : Boolean;
  2585. var TheReturnString : String;  { Internal string holder }
  2586.     TheResult       : Integer; { Internal int holder    }
  2587. begin
  2588.   Result := true;
  2589.   if TheDir <> '' then
  2590.   begin
  2591.     TheReturnString :=
  2592.      DoCStyleFormat( 'CWD %s' ,
  2593.       [ TheDir ] );
  2594.     { Put result in progress and status line }
  2595.     AddProgressText( TheReturnString );
  2596.     ShowProgressText( TheReturnString );
  2597.     { Send Password sequence }
  2598.     TheResult := PerformFTPCommand( 'CWD %s',
  2599.                                     [ TheDir ] );
  2600.     if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2601.     begin
  2602.       Result := false;
  2603.       FTPCommandInProgress := false;
  2604.       exit;
  2605.     end;
  2606.     repeat
  2607.       TheResult := GetFTPServerResponse( TheReturnString );
  2608.       { Put result in progress and status line }
  2609.       AddProgressText( TheReturnString );
  2610.       ShowProgressText( TheReturnString );
  2611.    until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2612.    FTPCommandInProgress := false;
  2613.    if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2614.     begin
  2615.       { Do clever C formatting trick }
  2616.       TheReturnString :=
  2617.        DoCStyleFormat( 'CWD to %s Failed!' ,
  2618.         [ TheDir ] );
  2619.       { Put result in progress and status line }
  2620.       AddProgressText( TheReturnString );
  2621.       ShowProgressErrorText( TheReturnString );
  2622.       { Signal error }
  2623.       Result := False;
  2624.       { leave }
  2625.       exit;
  2626.     end
  2627.     else Result := true; { Signal no problem }
  2628.   end;
  2629. end;
  2630.  
  2631. { This is the FTP components QUIT routine }
  2632. function TFTPComponent.Disconnect : Boolean;
  2633. var TheReturnString : String;  { Internal string holder }
  2634.     TheResult       : Integer; { Internal int holder    }
  2635. begin
  2636.   TheReturnString :=
  2637.    DoCStyleFormat( 'QUIT' ,
  2638.     [ nil ] );
  2639.   { Put result in progress and status line }
  2640.   AddProgressText( TheReturnString );
  2641.   ShowProgressText( TheReturnString );
  2642.   { Begin login sequence with user name }
  2643.   PerformFTPCommand( 'QUIT', [ nil ] );
  2644.   repeat
  2645.     TheResult := GetFTPServerResponse( TheReturnString );
  2646.     { Put result in progress and status line }
  2647.     AddProgressText( TheReturnString );
  2648.     ShowProgressText( TheReturnString );
  2649.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2650.   FTPCommandInProgress := false;
  2651.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2652.   begin
  2653.     { Do clever C formatting trick }
  2654.     TheReturnString :=
  2655.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2656.       [ nil ] );
  2657.     { Put result in progress and status line }
  2658.     AddProgressText( TheReturnString );
  2659.     ShowProgressErrorText( TheReturnString );
  2660.     { Signal error }
  2661.     Result := False;
  2662.     { leave }
  2663.     exit;
  2664.   end
  2665.   else Result := true; { Signal no problem }
  2666. end;
  2667.  
  2668. { This is the FTP components PWD routine }
  2669. function TFTPComponent.GetRemoteWorkingDirectory( var RemoteDir : String )
  2670.           : Boolean;
  2671. var TheReturnString : String;  { Internal string holder }
  2672.     TheResult       : Integer; { Internal int holder    }
  2673. begin
  2674.   TheReturnString :=
  2675.    DoCStyleFormat( 'PWD' ,
  2676.     [ nil ] );
  2677.   { Put result in progress and status line }
  2678.   AddProgressText( TheReturnString );
  2679.   ShowProgressText( TheReturnString );
  2680.   { Send Password sequence }
  2681.   TheResult := PerformFTPCommand( 'PWD',
  2682.                                   [ nil ] );
  2683.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2684.   begin
  2685.     Result := false;
  2686.     FTPCommandInProgress := false;
  2687.     exit;
  2688.   end;
  2689.   repeat
  2690.     TheResult := GetFTPServerResponse( TheReturnString );
  2691.     { Put result in progress and status line }
  2692.     AddProgressText( TheReturnString );
  2693.     ShowProgressText( TheReturnString );
  2694.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2695.   FTPCommandInProgress := false;
  2696.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2697.   begin
  2698.     { Do clever C formatting trick }
  2699.     TheReturnString :=
  2700.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2701.       [ nil ] );
  2702.     { Put result in progress and status line }
  2703.     AddProgressText( TheReturnString );
  2704.     ShowProgressErrorText( TheReturnString );
  2705.     { Signal error }
  2706.     Result := False;
  2707.     { leave }
  2708.     exit;
  2709.   end
  2710.   else
  2711.   begin
  2712.     Result := true; { Signal no problem }
  2713.     RemoteDir := TheReturnString; { Send back last string on faith }
  2714.   end;
  2715. end;
  2716.  
  2717. { This function sets up a listening port on socekt 2 and handle text replies }
  2718. function TFTPComponent.GetListeningPort : Integer;
  2719. var
  2720.   Address1 ,
  2721.   Address2 ,
  2722.   Address3 ,
  2723.   Address4        : integer; { Address integer conversions }
  2724.   IPAddress       : string;  { IP Address holder           }
  2725.   PortCommand     : string;  { Command holder              }
  2726.   TheResult       : Integer; { Result holder               }
  2727.   TheReturnString : String;  { ditto                       }
  2728. begin
  2729.   { Set up any port on socket 2 }
  2730.   Socket2.PortName := '0';
  2731.   { Listen on a socket }
  2732.   Socket2.CCSockListen;
  2733.   { Get the IP Address of socket 1 and convert it to numbers }
  2734.   IPAddress := Socket1.GetSocketIPAddress( Socket1.TheSocket );
  2735.   Address1 := StrToInt( copy( IPAddress , 1 , Pos( '.' , IPAddress ) -1 ));
  2736.   IPAddress := copy( IPAddress , Pos( '.' , IPAddress ) + 1 , 255 );
  2737.   Address2 := StrToInt( copy( IPAddress , 1 , Pos( '.' , IPAddress) -1 ));
  2738.   IPAddress := copy( IPAddress , Pos( '.' , IPAddress ) + 1 , 255 );
  2739.   Address3 := StrToInt( copy( IPAddress , 1 , Pos( '.' , IPAddress ) -1 ));
  2740.   Address4 := StrToInt( copy( IPAddress , Pos( '.' , IPAddress ) + 1 , 255 ));
  2741.   { Turn it into a command and add socket 2 stuff }
  2742.   PortCommand := format( 'PORT %d,%d,%d,%d,%d,%d' ,
  2743.    [ Address1 , Address2 , Address3 , Address4 ,
  2744.     StrToInt( Socket2.GetSocketPort( Socket2.TheMasterSocket )) Shr 8,
  2745.     StrToInt( Socket2.GetSocketPort( Socket2.TheMasterSocket )) and $ff ]);
  2746.   { Put result in progress and status line }
  2747.   AddProgressText( PortCommand + #13#10 );
  2748.   ShowProgressText( PortCommand  + #13#10 );
  2749.   TheResult := PerformFTPCommand( PortCommand , [nil] );
  2750.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2751.   begin
  2752.     Result := TCPIP_STATUS_FATAL_ERROR;
  2753.     FTPCommandInProgress := false;
  2754.     exit;
  2755.   end;
  2756.   repeat
  2757.     TheResult := GetFTPServerResponse( TheReturnString );
  2758.     { Put result in progress and status line }
  2759.     AddProgressText( TheReturnString );
  2760.     ShowProgressText( TheReturnString );
  2761.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2762.   FTPCommandInProgress := false;
  2763.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2764.   begin
  2765.     { Do clever C formatting trick }
  2766.     TheReturnString :=
  2767.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2768.       [ nil ] );
  2769.     { Put result in progress and status line }
  2770.     AddProgressText( TheReturnString );
  2771.     ShowProgressErrorText( TheReturnString );
  2772.     { Signal error }
  2773.     Result := TheResult;
  2774.     { leave }
  2775.     exit;
  2776.   end
  2777.   else
  2778.   begin
  2779.     { Return good result and leave }
  2780.     Result := TheResult;
  2781.     exit;
  2782.   end;
  2783. end;
  2784.  
  2785. { This function returns part of a unit text string }
  2786. function TFTPComponent.GetUNIXTextString( var StringIn : String ) : String;
  2787. var
  2788.   ReturnString : String;
  2789.   TheLength ,
  2790.   Counter_1   : integer;
  2791. begin
  2792.   TheLength := Length( StringIn );
  2793.   if TheLength > 1 then
  2794.   begin
  2795.     for Counter_1 := 1 to TheLength do
  2796.     begin
  2797.       if StringIn[ Counter_1 ] = #10 then
  2798.       begin
  2799.         ReturnString := HolderLine;
  2800.         HolderLine := '';
  2801.         StringIn := Copy( StringIn , Counter_1 + 1 , 255 );
  2802.         Result := ReturnString;
  2803.         exit;
  2804.       end
  2805.       else
  2806.       begin
  2807.         if StringIn[ Counter_1 ] <> #0 then
  2808.         begin
  2809.           if StringIn[ Counter_1 ] <> #13 then
  2810.            HolderLine := HolderLine + StringIn[ Counter_1 ];
  2811.         end
  2812.         else
  2813.         begin
  2814.           Result := '';
  2815.           StringIn := '';
  2816.         end;
  2817.       end;
  2818.     end;
  2819.   end;
  2820.   Result := '';
  2821.   StringIn := '';
  2822. end;
  2823.  
  2824. procedure TFTPComponent.GetFileNameFromUNIXFileName( var TheName : String );
  2825. var Counter_1 : Integer;
  2826.     ResultString : String;
  2827.     Finished : Boolean;
  2828. begin
  2829.   if Pos( 'TOTAL' , Uppercase( TheName )) <> 0 then
  2830.   begin
  2831.     TheName := '';
  2832.     exit;
  2833.   end;
  2834.   Counter_1 := Length( TheName );
  2835.   ResultString := '';
  2836.   Finished := false;
  2837.   while not Finished do
  2838.   begin
  2839.     if TheName[ Counter_1 ] <> ' ' then
  2840.     begin
  2841.       Counter_1 := Counter_1 - 1;
  2842.       if Counter_1 = 0 then
  2843.       begin
  2844.         ResultString := TheName;
  2845.         Finished := true;
  2846.       end;
  2847.     end
  2848.     else
  2849.     begin
  2850.       Finished := true;
  2851.       ResultString := Copy( TheName , Counter_1 + 1 , 255 );
  2852.     end;
  2853.   end;
  2854.   TheName := ResultString;
  2855. end;
  2856.  
  2857. { This is the FTP components get remote directory listing into a list box }
  2858. function TFTPComponent.GetRemoteDirectoryListing( TheListBox : TListBox )
  2859.           : Boolean;
  2860. var TheReturnString : String;  { Internal string holder }
  2861.     TheResult       : Integer; { Internal int holder    }
  2862.     InputString     : String;
  2863.     Through ,
  2864.     Finished        : Boolean;
  2865. begin
  2866.   TheListBox.Clear;
  2867.   TheListbox.Tag := 2;
  2868.   TheListBox.Items.Add('..');
  2869.   Result := true;
  2870.   TheReturnString :=
  2871.    DoCStyleFormat( 'TYPE A' ,
  2872.     [ nil ] );
  2873.   { Put result in progress and status line }
  2874.   AddProgressText( TheReturnString );
  2875.   ShowProgressText( TheReturnString );
  2876.   { Send Password sequence }
  2877.   TheResult := PerformFTPCommand( 'TYPE A',
  2878.                                   [ nil ] );
  2879.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2880.   begin
  2881.     Result := true;
  2882.     FTPCommandInProgress := false;
  2883.     exit;
  2884.   end;
  2885.   repeat
  2886.     TheResult := GetFTPServerResponse( TheReturnString );
  2887.     { Put result in progress and status line }
  2888.     AddProgressText( TheReturnString );
  2889.     ShowProgressText( TheReturnString );
  2890.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2891.   FTPCommandInProgress := false;
  2892.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2893.   begin
  2894.     { Do clever C formatting trick }
  2895.     TheReturnString :=
  2896.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2897.       [ nil ] );
  2898.     { Put result in progress and status line }
  2899.     AddProgressText( TheReturnString );
  2900.     ShowProgressErrorText( TheReturnString );
  2901.     { Signal error }
  2902.     Result := true;
  2903.     { leave }
  2904.     exit;
  2905.   end
  2906.   else
  2907.   begin
  2908.     { Set up socket 2 for listening }
  2909.     Socket2.AsynchMode := False;
  2910.     Socket2.NonAsynchTimeoutValue := 60;
  2911.     { do a listen and send command to server that this is receipt socket }
  2912.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  2913.     begin
  2914.       Socket2.CCSockCancelListen;
  2915.       exit;
  2916.     end;
  2917.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  2918.     TheResult := PerformFTPCommand( 'LIST' , [nil] );
  2919.     GetFTPServerResponse( TheReturnString );
  2920.     AddProgressText( TheReturnString );
  2921.     ShowProgressText( TheReturnString );
  2922.     Socket1.NonAsynchTimeoutValue := 30;
  2923.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  2924.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  2925.     begin
  2926.       TheReturnString :=
  2927.        DoCStyleFormat( 'Could not obtain remote directory!' ,
  2928.         [ nil ] );
  2929.       { Put result in progress and status line }
  2930.       AddProgressText( TheReturnString );
  2931.       ShowProgressErrorText( TheReturnString );
  2932.       Socket2.CCSockCancelListen;
  2933.       Result := true;
  2934.       exit;
  2935.     end;
  2936.     Socket2.CCSockAccept;
  2937.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  2938.     begin
  2939.       TheReturnString :=
  2940.        DoCStyleFormat( 'Could not establish receive socket!' ,
  2941.         [ nil ] );
  2942.       { Put result in progress and status line }
  2943.       AddProgressText( TheReturnString );
  2944.       ShowProgressErrorText( TheReturnString );
  2945.       Result := true;
  2946.       exit;
  2947.     end;
  2948.     Through := false;
  2949.     repeat
  2950.       TheReturnString := Socket2.StringData;
  2951.       if Length( TheReturnString ) = 0 then Through := true;
  2952.       if Length( TheReturnString ) > 0 then
  2953.       begin
  2954.         finished := false;
  2955.         while not finished do
  2956.         begin
  2957.           InputString := GetUNIXTextString( TheReturnString );
  2958.           if InputString = '' then Finished := true else
  2959.           begin
  2960.             GetFileNameFromUNIXFileName( InputString);
  2961.             If InputString <> '' then
  2962.             TheListBox.Items.Add( InputString );
  2963.           end;
  2964.         end;
  2965.       end;
  2966.       if GlobalAbortedFlag then
  2967.       begin
  2968.         Socket1.OutOfBand := 'ABOR'+#13#10;
  2969.         repeat
  2970.           TheResult := GetFTPServerResponse( TheReturnString );
  2971.           { Put result in progress and status line }
  2972.           AddProgressText( TheReturnString );
  2973.           ShowProgressText( TheReturnString );
  2974.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2975.         result := true;
  2976.         exit;
  2977.       end;
  2978.     until Through;
  2979.     GetFTPServerResponse( TheReturnString );
  2980.     AddProgressText( TheReturnString );
  2981.     ShowProgressText( TheReturnString );
  2982.     { cancel listening on second socket and close it }
  2983.     Socket2.CCSockCancelListen;
  2984.     Socket2.CCSockClose;
  2985.   end;
  2986.   FTPCommandInProgress := false;
  2987. end;
  2988.  
  2989. { This is the FTP components get remote directory listing into a list box }
  2990. function TFTPComponent.GetRemoteDirectoryListingToMemo : Boolean;
  2991. var TheReturnString : String;  { Internal string holder }
  2992.     TheResult       : Integer; { Internal int holder    }
  2993.     Through         : Boolean;
  2994. begin
  2995.   Result := true;
  2996.   TheReturnString :=
  2997.    DoCStyleFormat( 'TYPE A' ,
  2998.     [ nil ] );
  2999.   { Put result in progress and status line }
  3000.   AddProgressText( TheReturnString );
  3001.   ShowProgressText( TheReturnString );
  3002.   { Send Password sequence }
  3003.   TheResult := PerformFTPCommand( 'TYPE A',
  3004.                                   [ nil ] );
  3005.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  3006.   begin
  3007.     Result := true;
  3008.     FTPCommandInProgress := false;
  3009.     exit;
  3010.   end;
  3011.   repeat
  3012.     TheResult := GetFTPServerResponse( TheReturnString );
  3013.     { Put result in progress and status line }
  3014.     AddProgressText( TheReturnString );
  3015.     ShowProgressText( TheReturnString );
  3016.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  3017.   FTPCommandInProgress := false;
  3018.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  3019.   begin
  3020.     { Do clever C formatting trick }
  3021.     TheReturnString :=
  3022.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  3023.       [ nil ] );
  3024.     { Put result in progress and status line }
  3025.     AddProgressText( TheReturnString );
  3026.     ShowProgressErrorText( TheReturnString );
  3027.     { Signal error }
  3028.     Result := true;
  3029.     { leave }
  3030.     exit;
  3031.   end
  3032.   else
  3033.   begin
  3034.     { Set up socket 2 for listening }
  3035.     Socket2.AsynchMode := False;
  3036.     Socket2.NonAsynchTimeoutValue := 30;
  3037.     { do a listen and send command to server that this is receipt socket }
  3038.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  3039.     begin
  3040.       Socket2.CCSockCancelListen;
  3041.       exit;
  3042.     end;
  3043.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  3044.     TheResult := PerformFTPCommand( 'LIST' , [nil] );
  3045.     GetFTPServerResponse( TheReturnString );
  3046.     AddProgressText( TheReturnString );
  3047.     ShowProgressText( TheReturnString );
  3048.     Socket1.NonAsynchTimeoutValue := 30;
  3049.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  3050.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  3051.     begin
  3052.       TheReturnString :=
  3053.        DoCStyleFormat( 'Could not obtain remote directory!' ,
  3054.         [ nil ] );
  3055.       { Put result in progress and status line }
  3056.       AddProgressText( TheReturnString );
  3057.       ShowProgressErrorText( TheReturnString );
  3058.       Socket2.CCSockCancelListen;
  3059.       Result := true;
  3060.       exit;
  3061.     end;
  3062.     Socket2.CCSockAccept;
  3063.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  3064.     begin
  3065.       TheReturnString :=
  3066.        DoCStyleFormat( 'Could not establish receive socket!' ,
  3067.         [ nil ] );
  3068.       { Put result in progress and status line }
  3069.       AddProgressText( TheReturnString );
  3070.       ShowProgressErrorText( TheReturnString );
  3071.       Result := true;
  3072.       exit;
  3073.     end;
  3074.     Through := false;
  3075.     repeat
  3076.       TheReturnString := Socket2.StringData;
  3077.       if Length( TheReturnString ) = 0 then Through := true;
  3078.       if Length( TheReturnString ) > 0 then
  3079.       begin
  3080.         { Put result in progress and status line }
  3081.         AddProgressText( TheReturnString );
  3082.         ShowProgressText( TheReturnString );
  3083.       end;
  3084.       if GlobalAbortedFlag then
  3085.       begin
  3086.         Socket1.OutOfBand := 'ABOR'+#13#10;
  3087.         repeat
  3088.           TheResult := GetFTPServerResponse( TheReturnString );
  3089.           { Put result in progress and status line }
  3090.           AddProgressText( TheReturnString );
  3091.           ShowProgressText( TheReturnString );
  3092.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  3093.         result := true;
  3094.         exit;
  3095.       end;
  3096.     until Through;
  3097.     GetFTPServerResponse( TheReturnString );
  3098.     AddProgressText( TheReturnString );
  3099.     ShowProgressText( TheReturnString );
  3100.     { cancel listening on second socket and close it }
  3101.     Socket2.CCSockCancelListen;
  3102.     Socket2.CCSockClose;
  3103.   end;
  3104. end;
  3105.  
  3106. { This is the FTP components get local directory listing into a list box }
  3107. function TFTPComponent.GetLocalDirectoryAndListing( var TheString : String;
  3108.                                                         TheListBox : TListBox )
  3109.           : Boolean;
  3110. var TheFLB : TFileListBox;
  3111. begin
  3112.   { Get the working directory }
  3113.   GetDir( 0 , TheString );
  3114.   { Clear incoming LB }
  3115.   TheListBox.Clear;
  3116.   TheListBox.Tag := 2;
  3117.   TheFLB := TFileListBox.Create( Application.MainForm );
  3118.   TheFLB.Visible := false;
  3119.   TheFLB.Parent := Application.MainForm;
  3120.   TheFLB.FileType := [ ftNormal , ftDirectory ];
  3121.   TheFLB.Directory := TheString;
  3122.   TheFLB.Update;
  3123.   TheListBox.Items.Assign( TheFLB.Items );
  3124.   TheFLB.Free;
  3125.   result := true;
  3126. end;
  3127.  
  3128. { This is a clever c-style formatting trick }
  3129. function TFTPComponent.DoCStyleFormat(
  3130.                 TheText      : string;
  3131.           const TheArguments : array of const ) : String;
  3132. begin
  3133.   Result := Format( TheText , TheArguments ) + #13#10;
  3134. end;
  3135.  
  3136. function TFTPComponent.GetQuotedString( TheString : String ) : String;
  3137. var TheIndex     : Integer; { Holder var }
  3138.     ResultString : String;  { ditto      }
  3139. begin
  3140.   { Find out if " present at all }
  3141.   TheIndex := Pos( '"' , TheString );
  3142.   If TheIndex = 0 then
  3143.   begin
  3144.     { If not, return null string and exit }
  3145.     Result := '';
  3146.     exit;
  3147.   end
  3148.   else
  3149.   begin
  3150.     { Get from first " to end of string in holder }
  3151.     ResultString := Copy( TheString , TheIndex + 1 , 255 );
  3152.     { Find position to second " }
  3153.     TheIndex := Pos( '"' , ResultString );
  3154.     { If no ending " then return whole string and leave }
  3155.     if TheIndex = 0 then
  3156.     begin
  3157.       Result := ResultString;
  3158.       exit;
  3159.     end
  3160.     else
  3161.     begin
  3162.       { Get internal text between quotes and exit }
  3163.       ResultString := Copy( ResultString , 1 , TheIndex - 1 );
  3164.       Result := ResultString;
  3165.     end;
  3166.   end;
  3167. end;
  3168.  
  3169. procedure TCCINetCCForm.UpdateGauge( BytesFinished , TotalToHandle : longint );
  3170. var
  3171.   Percentage : longint;
  3172. begin
  3173.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3174.   if TotalToHandle = 0 then exit;
  3175.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3176.   Gauge1.Progress := Percentage;
  3177.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3178.    ' bytes ' + FileNameToXFer + ' (' + IntToStr( Percentage ) + '% Done)';
  3179. end;
  3180.  
  3181. procedure TCCINetCCForm.UpdateMailGauge( BytesFinished , TotalToHandle : longint );
  3182. var
  3183.   Percentage : longint;
  3184. begin
  3185.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3186.   if TotalToHandle = 0 then exit;
  3187.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3188.   Gauge1.Progress := Percentage;
  3189.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3190.    ' bytes mail (' + IntToStr( Percentage ) + '% Done)';
  3191. end;
  3192.  
  3193. procedure TCCINetCCForm.UpdateUUGauge( BytesFinished , TotalToHandle : longint );
  3194. var
  3195.   Percentage : longint;
  3196. begin
  3197.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3198.   if TotalToHandle = 0 then exit;
  3199.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3200.   Gauge1.Progress := Percentage;
  3201.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3202.    ' bytes UUCode (' + IntToStr( Percentage ) + '% Done)';
  3203.   Panel1.Show;
  3204. end;
  3205.  
  3206. { This procedure actually attempts to connect to the internet at an ftp site }
  3207. function TCCINetCCForm.DoFTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  3208. var TheReturnString : String; { Display results of connection in status lines }
  3209. begin
  3210.   { Create the component }
  3211.   Result := false;
  3212.   { Do busy cursors }
  3213.   SetHGCursors;
  3214.   if not TheFTPComponent.EstablishConnection( PCRPointer ) then
  3215.   begin
  3216.     { Do saved cursors }
  3217.     TheFTPComponent.FTPCommandInProgress := false;
  3218.     TheFTPComponent.Connection_Established := false;
  3219.     SetNormalCursors;
  3220.     exit;
  3221.   end
  3222.   else
  3223.   begin { Connected; continue login process }
  3224.     if not TheFTPComponent.LoginUser( PCRPointer ) then
  3225.     begin
  3226.       { Do saved cursors }
  3227.       TheFTPComponent.FTPCommandInProgress := false;
  3228.       TheFTPComponent.Connection_Established := false;
  3229.       SetNormalCursors;
  3230.       exit;
  3231.     end;
  3232.     if not TheFTPComponent.SendPassword( PCRPointer ) then
  3233.     begin
  3234.       { Do saved cursors }
  3235.       TheFTPComponent.FTPCommandInProgress := false;
  3236.       TheFTPComponent.Connection_Established := false;
  3237.       SetNormalCursors;
  3238.       exit;
  3239.     end;
  3240.     if not TheFTPComponent.SetRemoteStartupDirectory( PCRPointer ) then
  3241.     begin
  3242.       { Do saved cursors }
  3243.       SetNormalCursors;
  3244.       TheFTPComponent.Connection_Established := false;
  3245.       TheFTPComponent.FTPCommandInProgress := false;
  3246.       exit;
  3247.     end;
  3248.     if not TheFTPComponent.GetRemoteWorkingDirectory( TheReturnString ) then
  3249.     begin
  3250.       { Do saved cursors }
  3251.       TheFTPComponent.Connection_Established := false;
  3252.       TheFTPComponent.FTPCommandInProgress := false;
  3253.       SetNormalCursors;
  3254.       exit;
  3255.     end;
  3256.     { Put up remote directory via PWD and strip quotes }
  3257.     Label4.Caption := TheFTPComponent.GetQuotedString( TheReturnString );
  3258.     { Get the listings of directories and exit OK }
  3259.     TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  3260.     TheFTPComponent.GetLocalDirectoryAndListing( TheReturnString ,
  3261.      Listbox2 );
  3262.     if Label5.Canvas.TextWidth( TheReturnString ) > Label5.Width then
  3263.      TheReturnString := TheFTPComponent.GetShortPathName( TheReturnString );
  3264.     Label5.Caption := TheReturnString;
  3265.     SetNormalCursors;
  3266.     Result := true;
  3267.     EnableFTPMenus;
  3268.     TheFTPComponent.FTPCommandInProgress := false;
  3269.     Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  3270.   end;
  3271. end;
  3272.  
  3273. { This procedure actually attempts to connect to the internet at an nntp site }
  3274. function TCCINetCCForm.DoNNTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  3275. begin
  3276.   { Create the component }
  3277.   Result := false;
  3278.   { Do busy cursors }
  3279.   SetHGCursors;
  3280.   if not TheNNTPComponent.EstablishConnection( PCRPointer ) then
  3281.   begin
  3282.     { Do saved cursors }
  3283.     TheNNTPComponent.NNTPCommandInProgress := false;
  3284.     TheNNTPComponent.Connection_Established := false;
  3285.     SetNormalCursors;
  3286.     exit;
  3287.   end
  3288.   else
  3289.   begin { Connected; continue login process }
  3290.     SetNormalCursors;
  3291.     Result := true;
  3292.     EnableNNTPMenus;
  3293.     TheNNTPComponent.NNTPCommandInProgress := false;
  3294.     Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  3295.   end;
  3296. end;
  3297.  
  3298. { This procedure actually attempts to disconnect to the internet at an ftp site}
  3299. procedure TCCINetCCForm.DoFTPDisconnect;
  3300. begin
  3301.   { Call QUIT command }
  3302.   TheFTPComponent.Disconnect;
  3303.   { Kill the socket }
  3304.   TheFTPComponent.Socket1.CCSockClose;
  3305. end;
  3306.  
  3307. { This procedure actually attempts to disconnect to the internet at an ftp site}
  3308. procedure TCCINetCCForm.DoNNTPDisconnect;
  3309. begin
  3310.   { Call QUIT command }
  3311.   TheNNTPComponent.Disconnect;
  3312.   { Kill the socket }
  3313.   TheNNTPComponent.Socket1.CCSockClose;
  3314. end;
  3315.  
  3316. { This procedure reads in the ini file and default path info }
  3317. procedure TCCINetCCForm.ReadIniData;
  3318. begin
  3319.   TheICCIniFile := TIniFile.Create( 'CCICC.INI' );
  3320.   MailPath := TheICCIniFile.ReadString( 'Paths','MailPath','C:\WINDOWS' );
  3321.   NewsPath := TheICCIniFile.ReadString( 'Paths','NewsPath','C:\WINDOWS' );
  3322.   FTPPath := TheICCIniFile.ReadString( 'Paths','FTPPath','C:\WINDOWS' );
  3323.   PasswordControlVector := TheICCIniFile.ReadInteger( 'Vectors','PWControl',2 );
  3324.   DefaultDownloadVector := TheICCIniFile.ReadInteger( 'Vectors','DefDL', 3 );
  3325.   TheAnonRedialVector := TheICCIniFile.ReadInteger( 'Vectors','AnonRD', 20 );
  3326.   NewsReadArticlePurgingVector := TheICCIniFile.ReadInteger( 'Vectors','NewsPurge', 1 );
  3327.   NewsPostQueueingVector := TheICCIniFile.ReadInteger( 'Vectors','NewsQueue', 1 );
  3328.   NewsReadArticleDisplayVector := TheICCIniFile.ReadInteger( 'Vectors','NewsRDisp', 1 );
  3329.   NewsUUMIMEVector := TheICCIniFile.ReadInteger( 'Vectors','NewsUUMIME', 2 );
  3330.   NewsInitialUpdateVector := TheICCIniFile.ReadInteger( 'Vectors','NewsInitUD', 1 );
  3331.   EMPasswordControlVector := TheICCIniFile.ReadInteger( 'Vectors','EMPWControl', 1 );
  3332.   EMRemoteDeletionVector  := TheICCIniFile.ReadInteger( 'Vectors','EMRemDel', 2 );
  3333.   EMChokeVector           := TheICCIniFile.ReadInteger( 'Vectors','EMChoke', 1 );
  3334.   EMDefaultDownloadVector := TheICCIniFile.ReadInteger( 'Vectors','EMInitUD', 1 );
  3335.   EMQueueVector           := TheICCIniFile.ReadInteger( 'Vectors','EMQueue', 1 );
  3336.   TheICCIniFile.Free;
  3337. end;
  3338.  
  3339. { This procedure writes out default path data to the ini file }
  3340. procedure TCCINetCCForm.WriteIniData;
  3341. begin
  3342.   TheICCIniFile := TIniFile.Create( 'CCICC.INI' );
  3343.   TheICCIniFile.WriteString( 'Paths','MailPath', MailPath );
  3344.   TheICCIniFile.WriteString( 'Paths','NewsPath', NewsPath );
  3345.   TheICCIniFile.WriteString( 'Paths','FTPPath', FTPPath );
  3346.   TheICCIniFile.WriteInteger( 'Vectors','PWControl', PasswordControlVector );
  3347.   TheICCIniFile.WriteInteger( 'Vectors','DefDL', DefaultDownloadVector );
  3348.   TheICCIniFile.WriteInteger( 'Vectors','AnonRD', TheAnonRedialVector );
  3349.   TheICCIniFile.WriteInteger( 'Vectors','NewsPurge',
  3350.    NewsReadArticlePurgingVector );
  3351.   TheICCIniFile.WriteInteger( 'Vectors','NewsQueue', NewsPostQueueingVector );
  3352.   TheICCIniFile.WriteInteger( 'Vectors','NewsRDisp',
  3353.    NewsReadArticleDisplayVector );
  3354.   TheICCIniFile.WriteInteger( 'Vectors','NewsUUMIME', NewsUUMIMEVector );
  3355.   TheICCIniFile.WriteInteger( 'Vectors','NewsInitUD', NewsInitialUpdateVector );
  3356.   TheICCIniFile.WriteInteger( 'Vectors','EMPWControl', EMPasswordControlVector );
  3357.   TheICCIniFile.WriteInteger( 'Vectors','EMRemDel', EMRemoteDeletionVector );
  3358.   TheICCIniFile.WriteInteger( 'Vectors','EMChoke', EMChokeVector );
  3359.   TheICCIniFile.WriteInteger( 'Vectors','EMInitUD', EMDefaultDownloadVector );
  3360.   TheICCIniFile.WriteInteger( 'Vectors','EMQueue', EMQueueVector );
  3361.   TheICCIniFile.Free;
  3362. end;
  3363.  
  3364. { Procedure to load the FTP Site list }
  3365. procedure TCCINetCCForm.LoadFTPSiteFile;
  3366. var TheTCRecord : PConnectionsRecord; { Generic TCR Pointer    }
  3367.     FTPSLName   : String;             { FTP Site List filename }
  3368.     Counter_1   : Integer;            { Loop counter           }
  3369. begin
  3370.   { Create the sites list list }
  3371.   TheFTPSiteList := TList.Create;
  3372.   { Set up the FTP sites list file name }
  3373.   FTPSLName := FTPPath + '\FTPSITES.TCR';
  3374.   { If the FTP Site List exists load it in }
  3375.   if FileExists( FTPSLName ) then
  3376.   begin
  3377.     { set up the file and open it }
  3378.     AssignFile( TheFTPSiteFile , FTPSLName );
  3379.     Reset( TheFTPSiteFile );
  3380.     { read in the records }
  3381.     for Counter_1 := 0 to FileSize( TheFTPSiteFile ) - 1 do
  3382.     begin
  3383.       { Create the TCRecord }
  3384.       New( TheTCRecord );
  3385.       { Read in the data record }
  3386.       Seek( TheFTPSiteFile , Counter_1 );
  3387.       Read( TheFTPSiteFile , TheTCRecord^ );
  3388.       { Add the record to the list }
  3389.       TheFTPSiteList.Add( TheTCRecord );
  3390.     end;
  3391.     { close the file }
  3392.     CloseFile( TheFTPSiteFile );
  3393.   end
  3394.   else
  3395.   { Otherwise create a default one with a few anonymous sites }
  3396.   begin
  3397.     { create new record }
  3398.     New( TheTCRecord );
  3399.     { fill in its info }
  3400.     with TheTCRecord^ do
  3401.     begin
  3402.       CProfile   := 'Winsite Windows Archive';
  3403.       CIPAddress := 'ftp.winsite.com';
  3404.       CUserName  := 'anonymous';
  3405.       CPassword  := 'guest@nowhere.com';
  3406.       CStartDir  := '/pub';
  3407.     end;
  3408.     { add it to the list }
  3409.     { do it three more times }
  3410.     TheFTPSiteList.Add( TheTCRecord );
  3411.     New( TheTCRecord );
  3412.     with TheTCRecord^ do
  3413.     begin
  3414.       CProfile   := 'Digital Equipment Corp';
  3415.       CIPAddress := 'gatekeeper.dec.com';
  3416.       CUserName  := 'anonymous';
  3417.       CPassword  := 'guest@nowhere.com';
  3418.       CStartDir  := '/pub';
  3419.     end;
  3420.     TheFTPSiteList.Add( TheTCRecord );
  3421.     New( TheTCRecord );
  3422.     with TheTCRecord^ do
  3423.     begin
  3424.       CProfile   := 'Microsoft FTP Site';
  3425.       CIPAddress := 'ftp.microsoft.com';
  3426.       CUserName  := 'anonymous';
  3427.       CPassword  := 'guest@nowhere.com';
  3428.       CStartDir  := '/pub';
  3429.     end;
  3430.     TheFTPSiteList.Add( TheTCRecord );
  3431.     New( TheTCRecord );
  3432.     with TheTCRecord^ do
  3433.     begin
  3434.       CProfile   := 'Oakland MSDOS Archive';
  3435.       CIPAddress := 'oak.oakland.edu';
  3436.       CUserName  := 'anonymous';
  3437.       CPassword  := 'guest@nowhere.com';
  3438.       CStartDir  := '/pub';
  3439.     end;
  3440.     TheFTPSiteList.Add( TheTCRecord );
  3441.     { create the file and write out the data, then close it }
  3442.     AssignFile( TheFTPSiteFile , FTPSLName );
  3443.     Rewrite( TheFTPSiteFile );
  3444.     for Counter_1 := 0 to 3 do
  3445.     begin
  3446.       TheTCRecord :=
  3447.        PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] );
  3448.       Seek( TheFTPSiteFile , Counter_1 );
  3449.       Write( TheFTPSiteFile , TheTCRecord^ );
  3450.     end;
  3451.     CloseFile( TheFTPSiteFile );
  3452.   end;
  3453.   { Create the working copy for use to make safe changes in info dlg }
  3454.   TheWorkingFTPSL := TList.Create;
  3455.   For Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  3456.   begin
  3457.     New( TheTCRecord );
  3458.     TheTCRecord^ := PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] )^;
  3459.     TheWorkingFTPSL.Add( TheTCRecord );
  3460.   end;
  3461. end;
  3462.  
  3463. { Procedure to load the NNTP Site list }
  3464. procedure TCCINetCCForm.LoadNNTPSiteFile;
  3465. var TheNGRecord : PConnectionsRecord; { Generic TCR Pointer    }
  3466.     NNTPSLName  : String;             { NNTP Site List filename }
  3467.     Counter_1   : Integer;            { Loop counter           }
  3468. begin
  3469.   { Create the sites list list }
  3470.   TheNewsServerList := TList.Create;
  3471.   { Set up the FTP sites list file name }
  3472.   NNTPSLName := NewsPath + '\NNTPSITE.TCR';
  3473.   { If the FTP Site List exists load it in }
  3474.   if FileExists( NNTPSLName ) then
  3475.   begin
  3476.     { set up the file and open it }
  3477.     AssignFile( TheNewsServerFile , NNTPSLName );
  3478.     Reset( TheNewsServerFile );
  3479.     { read in the records }
  3480.     for Counter_1 := 0 to FileSize( TheNewsServerFile ) - 1 do
  3481.     begin
  3482.       { Create the TCRecord }
  3483.       New( TheNGRecord );
  3484.       { Read in the data record }
  3485.       Seek( TheNewsServerFile , Counter_1 );
  3486.       Read( TheNewsServerFile , TheNGRecord^ );
  3487.       { Add the record to the list }
  3488.       TheNewsServerList.Add( TheNGRecord );
  3489.     end;
  3490.     { close the file }
  3491.     CloseFile( TheNewsServerFile );
  3492.   end
  3493.   else
  3494.   { Otherwise create a default one with a generic news site (?) }
  3495.   begin
  3496.     { create new record }
  3497.     New( TheNGRecord );
  3498.     { fill in its info }
  3499.     with TheNGRecord^ do
  3500.     begin
  3501.       CProfile   := 'My News Server';
  3502.       CIPAddress := 'news.myprovider.com';
  3503.       CUserName  := '';
  3504.       CPassword  := '';
  3505.       CStartDir  := '';
  3506.     end;
  3507.     { add it to the list }
  3508.     { do it three more times }
  3509.     TheNewsServerList.Add( TheNGRecord );
  3510.     { create the file and write out the data, then close it }
  3511.     AssignFile( TheNewsServerFile , NNTPSLName );
  3512.     Rewrite( TheNewsServerFile );
  3513.     TheNGRecord :=
  3514.        PConnectionsRecord( TheNewsServerList.Items[ 0 ] );
  3515.       Seek( TheNewsServerFile , 0 );
  3516.       Write( TheNewsServerFile , TheNGRecord^ );
  3517.     CloseFile( TheNewsServerFile );
  3518.   end;
  3519.   TheWorkingNSSL := TList.Create;
  3520.   For Counter_1 := 0 to TheNewsServerList.Count - 1 do
  3521.   begin
  3522.     New( TheNGRecord );
  3523.     TheNGRecord^ := PConnectionsRecord( TheNewsServerList.Items[ Counter_1 ] )^;
  3524.     TheWorkingNSSL.Add( TheNGRecord );
  3525.   end;
  3526. end;
  3527.  
  3528. { This procedure saves off the FTP Site List }
  3529. procedure TCCINetCCForm.SaveFTPSiteFile;
  3530. var TheTCRecord : PConnectionsRecord; { The TC Record pointer  }
  3531.     FTPSLName   : String;             { FTP Site List filename }
  3532.     Counter_1   : Integer;            { Loop counter           }
  3533. begin
  3534.   { Set up the file name }
  3535.   FTPSLName := FTPPath + '\FTPSITES.TCR';
  3536.   { Assign the file }
  3537.   AssignFile( TheFTPSiteFile , FTPSLName );
  3538.   { Rewrite it }
  3539.   Rewrite( TheFTPSiteFile );
  3540.   { run the list through the procedure }
  3541.   for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  3542.   begin
  3543.     { get the record from the list }
  3544.     TheTCRecord :=
  3545.      PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] );
  3546.     { Do the seek/write }
  3547.     Seek( TheFTPSiteFile , Counter_1 );
  3548.     Write( TheFTPSiteFile , TheTCRecord^ );
  3549.     { free the record }
  3550.     Dispose( TheTCRecord );
  3551.   end;
  3552.   { Close the file }
  3553.   CloseFile( TheFTPSiteFile );
  3554.   { Free the list pointers }
  3555.   TheFTPSiteList.Free;
  3556.   TheWorkingFTPSL.Free;
  3557. end;
  3558.  
  3559. { This procedure saves off the FTP Site List }
  3560. procedure TCCINetCCForm.SaveNNTPSiteFile;
  3561. var TheNGRecord : PConnectionsRecord; { The TC Record pointer   }
  3562.     NNTPSLName   : String;            { NNTP Site List filename }
  3563.     Counter_1   : Integer;            { Loop counter           }
  3564. begin
  3565.   { Set up the file name }
  3566.   NNTPSLName := NewsPath + '\NNTPSITE.TCR';
  3567.   { Assign the file }
  3568.   AssignFile( TheNewsServerFile , NNTPSLName );
  3569.   { Rewrite it }
  3570.   Rewrite( TheNewsServerFile );
  3571.   { run the list through the procedure }
  3572.   for Counter_1 := 0 to TheNewsServerList.Count - 1 do
  3573.   begin
  3574.     { get the record from the list }
  3575.     TheNGRecord :=
  3576.      PConnectionsRecord( TheNewsServerList.Items[ Counter_1 ] );
  3577.     { Do the seek/write }
  3578.     Seek( TheNewsServerFile , Counter_1 );
  3579.     Write( TheNewsServerFile , TheNGRecord^ );
  3580.     { free the record }
  3581.     Dispose( TheNGRecord );
  3582.   end;
  3583.   { Close the file }
  3584.   CloseFile( TheNewsServerFile );
  3585.   { Free the list pointers }
  3586.   TheNewsServerList.Free;
  3587.   TheWorkingNSSL.Free;
  3588. end;
  3589.  
  3590. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3591. procedure TCCINetCCForm.SetupFTPSiteLists;
  3592. var Counter_1  : Integer;            { Loop counter        }
  3593. begin
  3594.   { Set up display for main form }
  3595.   CCINetCCForm.Tag := 2;
  3596.   CCINetCCForm.Caption := 'CC Internet Command Center -- FTP Mode';
  3597.   CCINetCCForm.ViewWinsockInfo1.Enabled := false;
  3598.   CCINetCCForm.FTP1.Enabled := false;
  3599.   CCINetCCForm.FTP2.Enabled := true;
  3600.   CCINetCCForm.Label1.Caption := 'FTP Site:';
  3601.   CCINetCCForm.Button1.Caption := 'Connect';
  3602.   CCINetCCForm.Label4.Caption := 'Local Dir';
  3603.   CCINetCCForm.Label5.Caption := 'Remote Dir';
  3604.   { Set tag for FTP stuff }
  3605.   CCICInfoDlg.Tag := 2;
  3606.   { set up caption of main label }
  3607.   CCICInfoDlg.Label2.Caption := 'FTP Sites';
  3608.   { hide outline panel }
  3609.   CCICInfoDlg.Panel6.Visible := false;
  3610.   { clear the list box }
  3611.   CCICInfoDlg.ListBox2.Clear;
  3612.   CCINetCCForm.ComboBox1.Clear;
  3613.   { add profile strings to the list box }
  3614.   for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  3615.   begin
  3616.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  3617.      TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  3618.     CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  3619.      TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  3620.   end;
  3621.   { Set up caption of special button }
  3622.   CCICInfoDlg.Button1.Caption := 'Anonymous Login';
  3623.   { Start with top record }
  3624.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  3625.   CCINetCCForm.ComboBox1.ItemIndex := 0;
  3626.   { put in data from top record and reset captions }
  3627.   with PConnectionsRecord( TheFTPSiteList.Items[ 0 ] )^ do
  3628.   begin
  3629.     with CCICInfoDlg do
  3630.     begin
  3631.       Edit1.Text := CProfile;
  3632.       Panel2.Caption := '            Name:';
  3633.       Edit2.Text := CIPAddress;
  3634.       Panel3.Caption := '     IP Address:';
  3635.       Edit3.Text := CUserName;
  3636.       Panel5.Caption := '    User Name:';
  3637.       case PasswordControlVector of
  3638.         1 : Edit4.Text := CPassword;
  3639.         2 : Edit4.Text := '**********';
  3640.       end;
  3641.       Panel8.Caption := '      Password:';
  3642.       Edit5.Text := CStartDir;
  3643.       Panel9.Caption := '    Starting Dir:';
  3644.     end;
  3645.   end;
  3646. end;
  3647.  
  3648. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3649. procedure TCCINetCCForm.SetupNNTPSiteLists;
  3650. begin
  3651.   { Set up display for main form }
  3652.   CCINetCCForm.Tag := 4; { Usenet News Tag }
  3653.   CCINetCCForm.Caption := 'CC Internet Command Center -- Usenet News Mode';
  3654.   CCINetCCForm.ViewWinsockInfo1.Enabled := false;
  3655.   CCINetCCForm.FTP1.Enabled := true;
  3656.   CCINetCCForm.FTP2.Enabled := false;
  3657.   CCINetCCForm.UsenetNws1.Enabled := false;
  3658.   CCINetCCForm.News1.Enabled := true;
  3659.   CCINetCCForm.Label1.Caption := 'NNTP Server:';
  3660.   CCINetCCForm.Button1.Caption := 'Connect';
  3661.   CCINetCCForm.Label4.Caption := 'SubScribed Groups';
  3662.   CCINetCCForm.Label5.Caption := 'Unread Articles';
  3663.   { Create the working copy for use to make safe changes in info dlg }
  3664. end;
  3665.  
  3666. { This method saves off the Newsgroup and Article Lists }
  3667. procedure TCCINetCCForm.SaveNNTPNewsGroupLists;
  3668. var TheNGRecord : PNewsGroupRecord; { Generic NGR Pointer       }
  3669.     TheNGARecord : PNewsGroupArticleRecord; {  }
  3670.     WorkingList : TList;
  3671.     Counter_1 ,
  3672.     Counter_2   : Integer;          { Loop counter              }
  3673.     NNTPNGLName ,                   { NewsGroup Articles fname  }
  3674.     NNTPARName  : String;           { NNTP NewsRC filename      }
  3675. begin
  3676.   { Abort if no server to select }
  3677.   if ComboBox1.ItemIndex = -1 then exit;
  3678.   { Get number of server in list }
  3679.   WhichServer := ComboBox1.ItemIndex;
  3680.   { Set up the FTP sites list file name }
  3681.   NNTPNGLName := NewsPath + '\NEWSRC ' + IntToStr( WhichServer ) + '.NRC';
  3682.   { If the FTP Site List exists load it in }
  3683.   { set up the file and open it }
  3684.   AssignFile( TheNewsRCFile , NNTPNGLName );
  3685.   ReWrite( TheNewsRCFile );
  3686.   { read in the records }
  3687.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3688.   begin
  3689.     { Create the TCRecord }
  3690.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  3691.     { Read in the data record }
  3692.     Seek( TheNewsRCFile , Counter_1 );
  3693.     Write( TheNewsRCFile , TheNGRecord^ );
  3694.     { Add the record to the list }
  3695.     WorkingList := TList( TheNGRecord^.GLTag );
  3696.     if WorkingList.Count > 0 then
  3697.     begin
  3698.       NNTPARName := TheNGRecord^.GFileName;
  3699.       TheNGArticlesList := TList.Create;
  3700.       AssignFile( TheNewsArticleFile , NewsPath + '\' + NNTPARName );
  3701.       ReWrite( TheNewsArticleFile );
  3702.       for Counter_2 := 0 to WorkingList.Count - 1 do
  3703.       begin
  3704.         TheNGARecord :=
  3705.          PNewsGroupArticleRecord( WorkingList.Items[ Counter_2 ] );
  3706.         Seek( TheNewsArticleFile , Counter_2 );
  3707.         Write( TheNewsArticleFile , TheNGARecord^ );
  3708.         Dispose( TheNGARecord );
  3709.       end;
  3710.       CloseFile( TheNewsArticleFile );
  3711.     end;
  3712.     WorkingList.Free;
  3713.     Dispose( TheNGRecord );
  3714.   end;
  3715.   { close the file }
  3716.   CloseFile( TheNewsRCFile );
  3717.   { Free the list itself }
  3718.   TheNewsRCList.Free;
  3719. end;
  3720.  
  3721. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3722. procedure TCCINetCCForm.SetupNNTPNewsGroupLists;
  3723. var TheNGRecord : PNewsGroupRecord; { Generic NGR Pointer       }
  3724.     TheNGARecord : PNewsGroupArticleRecord; {  }
  3725.     Counter_1 ,
  3726.     Counter_2   : Integer;          { Loop counter              }
  3727.     NNTPNGLName ,                   { NewsGroup Articles fname  }
  3728.     NNTPARName  : String;           { NNTP NewsRC filename      }
  3729. begin
  3730.   { Abort if no server to select }
  3731.   if ComboBox1.ItemIndex = -1 then exit;
  3732.   { Get number of server in list }
  3733.   WhichServer := ComboBox1.ItemIndex;
  3734.   { Create the sites list list }
  3735.   TheNewsRCList := TList.Create;
  3736.   { Set up the FTP sites list file name }
  3737.   NNTPNGLName := NewsPath + '\NEWSRC ' + IntToStr( WhichServer ) + '.NRC';
  3738.   { If the FTP Site List exists load it in }
  3739.   if FileExists( NNTPNGLName ) then
  3740.   begin
  3741.     { set up the file and open it }
  3742.     AssignFile( TheNewsRCFile , NNTPNGLName );
  3743.     Reset( TheNewsRCFile );
  3744.     { read in the records }
  3745.     for Counter_1 := 0 to FileSize( TheNewsRCFile ) - 1 do
  3746.     begin
  3747.       { Create the TCRecord }
  3748.       New( TheNGRecord );
  3749.       { Read in the data record }
  3750.       Seek( TheNewsRCFile , Counter_1 );
  3751.       Read( TheNewsRCFile , TheNGRecord^ );
  3752.       { Add the record to the list }
  3753.       TheNewsRCList.Add( TheNGRecord );
  3754.     end;
  3755.     { close the file }
  3756.     CloseFile( TheNewsRCFile );
  3757.   end
  3758.   else
  3759.   { Otherwise create a default one with 3 delphi newsgroups }
  3760.   begin
  3761.     { create new record }
  3762.     New( TheNGRecord );
  3763.     { fill in its info }
  3764.     with TheNGRecord^ do
  3765.     begin
  3766.       GName                := 'Delphi Comps';
  3767.       GRealName            := 'comp.lang.pascal.delphi.components';
  3768.       GLowest              := 0;
  3769.       GHighest             := 0;
  3770.       GPostable            := true;
  3771.       GSubscribed          := true;
  3772.       GTotalArticles       := 0;
  3773.       GTotalAvailable      := 0;
  3774.       GLowestAvailable     := 0;
  3775.       GHighestAvailable    := 0;
  3776.       GTotalUnReadArticles := 0;
  3777.       GIDNumber            := 1;
  3778.       GFileName            := 'NL' + IntToStr( WhichServer ) + 'G1.NGR';
  3779.       GLTag                := 0;
  3780.     end;
  3781.     { add it to the list }
  3782.     TheNewsRCList.Add( TheNGRecord );
  3783.     { create new record }
  3784.     New( TheNGRecord );
  3785.     { fill in its info }
  3786.     with TheNGRecord^ do
  3787.     begin
  3788.       GName                := 'Delphi DB';
  3789.       GRealName            := 'comp.lang.pascal.delphi.databases';
  3790.       GLowest              := 0;
  3791.       GHighest             := 0;
  3792.       GPostable            := true;
  3793.       GSubscribed          := true;
  3794.       GTotalArticles       := 0;
  3795.       GTotalAvailable      := 0;
  3796.       GLowestAvailable     := 0;
  3797.       GHighestAvailable    := 0;
  3798.       GTotalUnReadArticles := 0;
  3799.       GIDNumber            := 2;
  3800.       GFileName            := 'NL' + IntToStr( WhichServer ) + 'G2.NGR';
  3801.       GLTag                := 0;
  3802.     end;
  3803.     { add it to the list }
  3804.     TheNewsRCList.Add( TheNGRecord );
  3805.     { create new record }
  3806.     New( TheNGRecord );
  3807.     { fill in its info }
  3808.     with TheNGRecord^ do
  3809.     begin
  3810.       GName                := 'Delphi Misc';
  3811.       GRealName            := 'comp.lang.pascal.delphi.misc';
  3812.       GLowest              := 0;
  3813.       GHighest             := 0;
  3814.       GPostable            := true;
  3815.       GSubscribed          := true;
  3816.       GTotalArticles       := 0;
  3817.       GTotalAvailable      := 0;
  3818.       GLowestAvailable     := 0;
  3819.       GHighestAvailable    := 0;
  3820.       GTotalUnReadArticles := 0;
  3821.       GIDNumber            := 3;
  3822.       GFileName            := 'NL' + IntToStr( WhichServer ) + 'G3.NGR';
  3823.       GLTag                := 0;
  3824.     end;
  3825.     { add it to the list }
  3826.     TheNewsRCList.Add( TheNGRecord );
  3827.     { create the file and write out the data, then close it }
  3828.     AssignFile( TheNewsRCFile , NNTPNGLName );
  3829.     Rewrite( TheNewsRCFile );
  3830.     for Counter_1 := 0 to 2 do
  3831.     begin
  3832.       TheNGRecord :=
  3833.        PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  3834.       Seek( TheNewsRCFile , Counter_1 );
  3835.       Write( TheNewsRCFile , TheNGRecord^ );
  3836.     end;
  3837.     CloseFile( TheNewsRCFile );
  3838.   end;
  3839.   { Load in Articles Records and create storage lists }
  3840.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3841.   begin
  3842.     NNTPARName := PNewsGroupRecord(
  3843.      TheNewsRCList.Items[ Counter_1 ] )^.GFileName;
  3844.     if FileExists( NewsPath + '\' + NNTPARName ) then
  3845.     begin
  3846.       TheNGArticlesList := TList.Create;
  3847.       AssignFile( TheNewsArticleFile , NewsPath + '\' + NNTPARName );
  3848.       Reset( TheNewsArticleFile );
  3849.       for Counter_2 := 0 to FileSize( TheNewsArticleFile ) - 1 do
  3850.       begin
  3851.         New( TheNGARecord );
  3852.         Seek( TheNewsArticleFile , Counter_2 );
  3853.         Read( TheNewsArticleFile , TheNGARecord^ );
  3854.         TheNGArticlesList.Add( TheNGARecord );
  3855.       end;
  3856.       CloseFile( TheNewsArticleFile );
  3857.       PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] )^.GLTag :=
  3858.        Longint( TheNGArticlesList );
  3859.     end
  3860.     else
  3861.     begin
  3862.       TheNGArticlesList := TList.Create;
  3863.       PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] )^.GLTag :=
  3864.        Longint( TheNGArticlesList );
  3865.     end;
  3866.   end;
  3867.   { Create working Newsgroup list for later }
  3868.   TheWorkingNRCSL := TList.Create;
  3869.   For Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3870.   begin
  3871.     New( TheNGRecord );
  3872.     TheNGRecord^ := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] )^;
  3873.     TheWorkingNRCSL.Add( TheNGRecord );
  3874.   end;
  3875. end;
  3876.  
  3877. { This procedure populates LB2 with article subjects for any }
  3878. { available articles for a given newsgroup.                  }
  3879. procedure TCCINetCCForm.PopulateLB2WithArticleHeaders;
  3880. var Counter_1    : Integer;
  3881.     TheNGARecord : PNewsGroupArticleRecord;
  3882.     TempString   : String;
  3883. begin
  3884.   { Clear target list box }
  3885.   ListBox2.Clear;
  3886.   for Counter_1 := 0 to TheNGArticlesList.Count - 1 do
  3887.   begin
  3888.     TheNGARecord :=
  3889.      PNewsGroupArticleRecord( TheNGArticlesList.Items[ Counter_1 ] );
  3890.     TempString := '    [' + IntToStr( Counter_1 ) + '] ' +
  3891.      TheNGARecord^.NGASubject;
  3892.     if TheNGARecord^.NGADownloaded then TempString[ 1 ] :=
  3893.      'D';
  3894.     if TheNGARecord^.NGARead then TempString[ 3 ] := 'R';
  3895.     if TheNGARecord^.NGAPosted then TempString[ 3 ] := 'S';
  3896.     ListBox2.Items.Add( TempString );
  3897.   end;
  3898. end;
  3899.  
  3900. { This procedure swaps in the list of subscribed newsgroups to LB1 }
  3901. { and calls another procedure to populate LB2 with any available   }
  3902. { articles for the newsgroup.                                      }
  3903. procedure TCCINetCCForm.SetupNewsGroupListboxes;
  3904. var Counter_1   : Integer;
  3905.     TempString  : String;
  3906.     TheNGRecord : PNewsGroupRecord;
  3907. begin
  3908.   ListBox1.Clear;
  3909.   ListBox1.Tag := 5;
  3910.   ListBox2.Tag := 5;
  3911.   Label4.Caption := 'NewsGroups';
  3912.   Label5.Caption := 'Articles';
  3913.   if TheNewsRCList.Count = 0 then
  3914.   begin
  3915.     ListBox2.Clear;
  3916.     exit;
  3917.   end;
  3918.   ComboBox1.Clear;
  3919.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3920.   begin
  3921.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  3922.     TempString := TheNGRecord^.GName;
  3923.     ComboBox1.Items.Add( TheNGRecord^.GRealName );
  3924.     if TheNGRecord^.GSubscribed then
  3925.      TempString := '[S] ' + TempString else TempString := '[U] ' + TempString;
  3926.     TempString := TempString + '{' + IntToStr( TheNGRecord^.GTotalNew ) + '}';
  3927.     ListBox1.Items.Add( TempString );
  3928.   end;
  3929.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ 0 ] );
  3930.   TheNGArticlesList := TList( TheNGRecord^.GLTag );
  3931.   PopulateLB2WithArticleHeaders;
  3932.   Label1.Caption := 'NewsGroup:';
  3933.   ComboBox1.ItemIndex := 0;
  3934.   Button1.Caption := 'DL Article(s)';
  3935.   Tag := 5; { Set download vector }
  3936. end;
  3937.  
  3938. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3939. procedure TCCINetCCForm.SetupNNTPServersInfoDisplay;
  3940. var Counter_1  : Integer;            { Loop counter        }
  3941. begin
  3942.   { Set tag for NNTP stuff }
  3943.   CCICInfoDlg.Tag := 4; { Usenet News Tag -- servers }
  3944.   { set up caption of main label }
  3945.   CCICInfoDlg.Label2.Caption := 'News Server Sites';
  3946.   { hide outline panel }
  3947.   CCICInfoDlg.Panel6.Visible := false;
  3948.   CCICInfoDlg.Panel5.Visible := false;
  3949.   CCICInfoDlg.Panel8.Visible := false;
  3950.   CCICInfoDlg.Panel9.Visible := false;
  3951.   { clear the list box }
  3952.   CCICInfoDlg.ListBox2.Clear;
  3953.   CCINetCCForm.ComboBox1.Clear;
  3954.   { add profile strings to the list box }
  3955.   for Counter_1 := 0 to TheNewsServerList.Count - 1 do
  3956.   begin
  3957.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  3958.      TheNewsServerList.Items[ Counter_1 ] )^.CProfile );
  3959.     CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  3960.      TheNewsServerList.Items[ Counter_1 ] )^.CProfile );
  3961.   end;
  3962.   { Set up caption of special button }
  3963.   CCICInfoDlg.Button1.Visible := false;
  3964.   { Start with top record }
  3965.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  3966.   CCINetCCForm.ComboBox1.ItemIndex := 0;
  3967.   { put in data from top record and reset captions }
  3968.   with PConnectionsRecord( TheNewsServerList.Items[ 0 ] )^ do
  3969.   begin
  3970.     with CCICInfoDlg do
  3971.     begin
  3972.       Edit1.Text := CProfile;
  3973.       Panel2.Caption := '            Name:';
  3974.       Edit2.Text := CIPAddress;
  3975.       Panel3.Caption := '     IP Address:';
  3976.     end;
  3977.   end;
  3978. end;
  3979.  
  3980. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3981. procedure TCCINetCCForm.SetupNNTPNewsGroupsInfoDisplay;
  3982. var Counter_1  : Integer;            { Loop counter        }
  3983.     WorkingFileName : String;
  3984.     TheWorkingSL : TStringList;
  3985. begin
  3986.   { Set tag for NNTP stuff }
  3987.   CCICInfoDlg.Tag := 5; { Usenet News Tag -- newsgroups }
  3988.   { set up caption of main label }
  3989.   CCICInfoDlg.Label2.Caption := 'Active NewsGroups';
  3990.   { hide outline panel }
  3991.   CCICInfoDlg.Panel5.Visible := true;
  3992.   CCICInfoDlg.Panel6.Visible := true;
  3993.   CCICInfoDlg.Panel6.Height := 224;
  3994.   CCICInfoDlg.Panel6.Top := 120;
  3995.   CCICInfoDlg.Label1.Caption := 'Available NewsGroups';
  3996.   CCICInfoDlg.Panel8.Visible := false;
  3997.   CCICInfoDlg.Panel9.Visible := false;
  3998.   { clear the list box }
  3999.   CCICInfoDlg.ListBox2.Clear;
  4000.   { add profile strings to the list box }
  4001.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  4002.   begin
  4003.     CCICInfoDlg.ListBox2.Items.Add( PNewsGroupRecord(
  4004.      TheNewsRCList.Items[ Counter_1 ] )^.GName );
  4005.   end;
  4006.   { Set up caption of special button }
  4007.   CCICInfoDlg.Button1.Visible := true;
  4008.   CCICInfoDlg.Button1.Caption := 'Toggle Subscription';
  4009.   { Start with top record }
  4010.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  4011.   { put in data from top record and reset captions }
  4012.   with PNewsGroupRecord( TheNewsRCList.Items[ 0 ] )^ do
  4013.   begin
  4014.     with CCICInfoDlg do
  4015.     begin
  4016.       Edit1.Text := GName;
  4017.       Panel2.Caption := 'NG Name:';
  4018.       Edit2.Text := GRealName;
  4019.       Panel3.Caption := 'NG Real Name:';
  4020.       if GSubscribed then
  4021.       Edit3.Text := 'Subscribed' else Edit3.Text := 'UnSubscribed';
  4022.       Panel5.Caption := 'Status:';
  4023.     end;
  4024.   end;
  4025.   if newsgroupListloaded then exit;
  4026.   WorkingFileName := NewsPath + '\NEWSGRP.TXT';
  4027.   if FileExists( WorkingFileName ) then
  4028.   begin
  4029.     if MessageDlg( 'Load News Groups File? (Long operation...)',
  4030.      mtConfirmation,mbYesNoCancel,0) = mrYes then
  4031.     begin
  4032.       CCICInfoDlg.ListBox1.Clear;
  4033.       TheWorkingSL := TStringList.Create;
  4034.       try
  4035.         TheWorkingSL.LoadFromFile( WorkingFileName );
  4036.         CCICInfoDlg.ListBox1.Items.Assign( TheWorkingSL );
  4037.       except
  4038.         MessageDlg( 'News Group List Too Large! Use WordPad/Write to view ' +
  4039.                       NewsPath + '\NEWGRP.TXT' , mtInformation,[mbOK],0);
  4040.         TheWorkingSL.Free;
  4041.         NewsgroupListLoaded := false;
  4042.         exit;
  4043.       end;
  4044.       TheWorkingSL.Free;
  4045.       NewsgroupListLoaded := true;
  4046.     end;
  4047.   end;
  4048. end;
  4049.  
  4050. { This procedure scans a line of UNIX-style text for #10's and }
  4051. { outputs them as lines to the memo. It stops at #0.           }
  4052. procedure TCCINetCCForm.AddNullTermTextToMemo( TheTextToAdd   : String;
  4053.                                  TheMemoToAddTo : TMemo   );
  4054. var
  4055.   TextLength ,            { Total chars to output         }
  4056.   Counter_1    : integer; { Loop Index                    }
  4057. begin
  4058.   { Make the target memo visible just in case }
  4059.   TheMemoToAddTo.Visible := true;
  4060.   { Find total chars to output }
  4061.   TextLength := Length( TheTextToAdd );
  4062.   { If none then leave }
  4063.   if TextLength = 0 then exit;
  4064.   { Loop along the string }
  4065.   for Counter_1 := 1 to TextLength do
  4066.   begin
  4067.     { If hit ASCII 10 then assume end of line and output }
  4068.     if TheTextToAdd[ Counter_1 ] = #10 then
  4069.     begin
  4070.       { Use a try loop incase memo fills up }
  4071.       try
  4072.         { Add the line }
  4073.         TheMemoToAddTo.Lines.Add( TheLine );
  4074.       except
  4075.         { If memo fills up }
  4076.         on EOutOfResources do
  4077.         begin
  4078.           { Clear the old data }
  4079.           TheMemoToAddTo.Clear;
  4080.           { Output the new }
  4081.           TheMemoToAddTo.Lines.Add( TheLine );
  4082.         end;
  4083.       end;
  4084.       { clear the output buffer }
  4085.       TheLine := '';
  4086.     end
  4087.     else
  4088.     { Otherwise look for null terminator from Winsock }
  4089.     begin
  4090.       { If don't hit null terminator then add the char to op buffer }
  4091.       if TheTextToAdd[ Counter_1 ] <> #0 then
  4092.       begin
  4093.         TheLine := TheLine + TheTextToAdd[ Counter_1 ];
  4094.       end
  4095.       else break; { Otherwise drop out of the loop }
  4096.     end;
  4097.   end;
  4098. end;
  4099.  
  4100. { This function scans a line of UNIX-style text for #10's and }
  4101. { outputs the first line as its return value,stopping at #0.  }
  4102. function TCCINetCCForm.AddNullTermTextToLabel( TheTextToAdd   : String ) : String;
  4103. var
  4104.   TheLine      : String;  { Buffer to output current line }
  4105.   TextLength ,            { Total chars to output         }
  4106.   Counter_1    : integer; { Loop Index                    }
  4107. begin
  4108.   { Clear output buffer }
  4109.   TheLine := '';
  4110.   { Find total chars to output }
  4111.   TextLength := Length( TheTextToAdd );
  4112.   { If none then leave }
  4113.   if TextLength = 0 then
  4114.   begin
  4115.     { Return nothing }
  4116.     Result := '';
  4117.     { Leave }
  4118.     exit;
  4119.   end;
  4120.   { Loop along the string }
  4121.   for Counter_1 := 1 to TextLength do
  4122.   begin
  4123.     { If hit ASCII 10 then assume end of line and output }
  4124.     if TheTextToAdd[ Counter_1 ] = #10 then
  4125.     begin
  4126.       { Return first line }
  4127.       Result := TheLine;
  4128.       { Leave }
  4129.       exit;
  4130.     end
  4131.     else
  4132.     { Otherwise look for null terminator from Winsock }
  4133.     begin
  4134.       { If don't hit null terminator then add the char to op buffer }
  4135.       if TheTextToAdd[ Counter_1 ] <> #0 then
  4136.       begin
  4137.         TheLine := TheLine + TheTextToAdd[ Counter_1 ];
  4138.       end
  4139.       else break; { Otherwise drop out of the loop }
  4140.     end;
  4141.   end;
  4142.   { If hit #0 before #10 return buffer }
  4143.   Result := TheLine;
  4144. end;
  4145.  
  4146. { Show busy cursors }
  4147. procedure TCCINetCCForm.SetHGCursors;
  4148. begin
  4149.   CCInetCCForm.Cursor := crHourGlass;
  4150.   CCInetCCForm.Memo1.Cursor := crHourGlass;
  4151. end;
  4152.  
  4153. { Show normal cursors }
  4154. procedure TCCINetCCForm.SetNormalCursors;
  4155. begin
  4156.   CCInetCCForm.Cursor := crDefault;
  4157.   CCInetCCForm.Memo1.Cursor := crDefault;
  4158. end;
  4159.  
  4160. { Exit method }
  4161. procedure TCCINetCCForm.Exit1Click(Sender: TObject);
  4162. begin
  4163.   Close;
  4164. end;
  4165.  
  4166. { This method adds a line to the progress text stringlist  }
  4167. { If an exception occurs, the list is full, and it is auto }
  4168. { saved to the progress text file name, then cleared.      }
  4169. procedure TCCINetCCForm.AddProgressText( WhatText : String );
  4170. begin
  4171.   { Use a try..except loop to catch list overflows }
  4172.   try
  4173.     { Try the normal add }
  4174.     ProgressList.Add( WhatText );
  4175.   except
  4176.     { Any list error is assumed to be a list overflow }
  4177.     on EListError do
  4178.     begin
  4179.       { Save the list to the preset file name }
  4180.       ProgressList.SaveToFile( ProgressFileName );
  4181.       { Clear the list to make more room }
  4182.       ProgressList.Clear;
  4183.       { And redo the add; any further errors will except normally }
  4184.       ProgressList.Add( WhatText );
  4185.     end;
  4186.     { This might happen too! }
  4187.     on EOutOfResources do
  4188.     begin
  4189.       { Save the list to the preset file name }
  4190.       ProgressList.SaveToFile( ProgressFileName );
  4191.       { Clear the list to make more room }
  4192.       ProgressList.Clear;
  4193.       { And redo the add; any further errors will except normally }
  4194.       ProgressList.Add( WhatText );
  4195.     end;
  4196.   end;
  4197. end;
  4198.  
  4199. { This method either adds the progress line to the current memo }
  4200. { or puts it in the status caption at normal colors.            }
  4201. procedure TCCINetCCForm.ShowProgressText( WhatText : String );
  4202. begin
  4203.   { Use the POV to determine where to show progress info }
  4204.   case ProgressOutputVector of
  4205.     POV_MEMO : begin { Output into the memo  }
  4206.                  AddNullTermTextToMemo( WhatText , Memo1 );
  4207.                end;
  4208.     POV_STAT : begin { Output on status line }
  4209.                  { Set panel caption font to black }
  4210.                  Panel1.Font.Color := clBlack;
  4211.                  { Get the first line of text and put in caption }
  4212.                  Panel1.Caption := AddNullTermTextToLabel( WhatText );
  4213.                end;
  4214.   end;
  4215. end;
  4216.  
  4217. { This method is identical with SPT except sets status color to red and beeps }
  4218. procedure TCCINetCCForm.ShowProgressErrorText( WhatText : String );
  4219. begin
  4220.   { Do error beep }
  4221.   MessageBeep( mb_IconExclamation );
  4222.   { Use the POV to determine where to show progress info }
  4223.   case ProgressOutputVector of
  4224.     POV_MEMO : begin { Output into the memo  }
  4225.                  AddNullTermTextToMemo( WhatText , Memo1 );
  4226.                end;
  4227.     POV_STAT : begin { Output on status line }
  4228.                  { Set panel caption font to black }
  4229.                  Panel1.Font.Color := clRed;
  4230.                  { Get the first line of text and put in caption }
  4231.                  Panel1.Caption := AddNullTermTextToLabel( WhatText );
  4232.                end;
  4233.   end;
  4234. end;
  4235.  
  4236. { This is the boilerplate method used to handle Socket errors gracefully }
  4237. procedure TCCINetCCForm.SocketsErrorOccurred( Sender     : TObject;
  4238.                                               ErrorCode  : Integer;
  4239.                                               TheMessage : String   );
  4240. begin
  4241.   { Set the global error code flag }
  4242.   GlobalErrorCode := ErrorCode;
  4243.   { If a timeout error }
  4244.   if ErrorCode = WSAETIMEDOUT then
  4245.   begin
  4246.     { Set the aborted flag }
  4247.     GlobalAbortedFlag := True;
  4248.     { But clear the error code for graceful handling }
  4249.     GlobalErrorCode := 0;
  4250.   end
  4251.   else
  4252.   begin
  4253.     { Otherwise set the progress buffer to the error message }
  4254.     AddProgressText( TheMessage );
  4255.     { And show the progress text as set by option }
  4256.     ShowProgressErrorText( TheMessage );
  4257.   end;
  4258. end;
  4259.  
  4260. procedure TCCINetCCForm.FormCreate(Sender: TObject);
  4261. begin
  4262.   { Create the progress string list }
  4263.   ProgressList := TStringList.Create;
  4264.   { Create the file name for saving the progress list }
  4265.   ProgressFileName := ExpandFileName( 'PROGRESS.TXT' );
  4266.   { Default progress output to status line }
  4267.   ProgressOutputVector := POV_STAT;
  4268.   { Set password control stuff }
  4269.   PasswordControlVector := 2;
  4270.   CurrentPasswordString := 'guest@nowhere.com';
  4271.   CurrentRealPWString := 'guest@nowhere.com';
  4272.   NewMessageInProgress := false;
  4273.   EmailLoaded := false;
  4274.   NewsGroupListLoaded := false;
  4275.   { Get Ini file Data }
  4276.   ReadIniData;
  4277.   LoadFTPSiteFile;
  4278.   LoadNNTPSiteFile;
  4279.   LoadEMailServerFile;
  4280.   TheFTPComponent := TFTPComponent.Create( CCInetCCForm );
  4281.   TheFTPComponent.Parent := CCInetCCForm;
  4282.   TheNNTPComponent := TNNTPComponent.Create( CCInetCCForm );
  4283.   TheNNTPComponent.Parent := CCInetCCForm;
  4284.   ThePOP3SMTPComponent := TPOP3SMTPComponent.Create( CCInetCCForm );
  4285.   ThePOP3SMTPComponent.Parent := CCInetCCForm;
  4286.   TheUUObject := TUUCodingObject.Create( Self );
  4287.   TheUUObject.Parent := self;
  4288. end;
  4289.  
  4290. procedure TCCINetCCForm.FormDestroy(Sender: TObject);
  4291. begin
  4292.   { Free the progress text stringlist if assigned }
  4293.   if assigned( ProgressList ) then ProgressList.Free;
  4294.   { Save off the Ini data }
  4295.   WriteIniData;
  4296.   { Save and remove FTP site list stuff }
  4297.   SaveFTPSiteFile;
  4298.   SaveNNTPSiteFile;
  4299.   SaveEmailServerFile;
  4300.   if Assigned( TheFTPComponent ) then TheFTPComponent.Free;
  4301.   if Assigned( TheNNTPComponent ) then TheNNTPComponent.Free;
  4302.   if Assigned( ThePOP3SMTPComponent ) then ThePOP3SMTPComponent.Free;
  4303.   if Assigned( TheUUObject ) then TheUUObject.Free;
  4304. end;
  4305.  
  4306. procedure TCCINetCCForm.Description1Click(Sender: TObject);
  4307. var
  4308.   TempSocket : TCCSocket; { Temporary socket just to get Winsock info }
  4309.   TheData    : String;    { Holder for data                           }
  4310. begin
  4311.   { Create socket; auto calls WSAStartup }
  4312.   TempSocket := TCCSocket.Create( Self );
  4313.   { Do parent just for kicks; no longer needed }
  4314.   TempSocket.Parent := self;
  4315.   { Put in error handler }
  4316.   TempSocket.OnErrorOccurred := SocketsErrorOccurred;
  4317.   TheData := StrPas( TempSocket.Socket_WSA_Data.Description_String );
  4318.   { Display the Description String }
  4319.   AddProgressText( TheData );
  4320.   { And show the progress text as set by option }
  4321.   ShowProgressText( TheData );
  4322.   { Free the socket; auto calls WSACleanup }
  4323.   TempSocket.Free;
  4324. end;
  4325.  
  4326. procedure TCCINetCCForm.SystemStatus1Click(Sender: TObject);
  4327. var
  4328.   TempSocket : TCCSocket; { Temporary socket just to get Winsock info }
  4329.   TheData    : String;    { Holder for data                           }
  4330. begin
  4331.   { Create socket; auto calls WSAStartup }
  4332.   TempSocket := TCCSocket.Create( Self );
  4333.   { Do parent just for kicks; no longer needed }
  4334.   TempSocket.Parent := self;
  4335.   { Put in error handler }
  4336.   TempSocket.OnErrorOccurred := SocketsErrorOccurred;
  4337.   TheData := StrPas( TempSocket.Socket_WSA_Data.System_Status_String );
  4338.   { Display the Description String }
  4339.   AddProgressText( TheData );
  4340.   { And show the progress text as set by option }
  4341.   ShowProgressText( TheData );
  4342.   { Free the socket; auto calls WSACleanup }
  4343.   TempSocket.Free;
  4344. end;
  4345.  
  4346. procedure TCCINetCCForm.VendorSpecific1Click(Sender: TObject);
  4347. var
  4348.   TempSocket : TCCSocket; { Temporary socket just to get Winsock info }
  4349.   TheData    : String;    { Holder for data                           }
  4350. begin
  4351.   { Create socket; auto calls WSAStartup }
  4352.   TempSocket := TCCSocket.Create( Self );
  4353.   { Do parent just for kicks; no longer needed }
  4354.   TempSocket.Parent := self;
  4355.   { Put in error handler }
  4356.   TempSocket.OnErrorOccurred := SocketsErrorOccurred;
  4357.   TheData := StrPas( TempSocket.Socket_WSA_Data.Vendor_Specific_String );
  4358.   { Display the Description String }
  4359.   AddProgressText( TheData );
  4360.   { And show the progress text as set by option }
  4361.   ShowProgressText( TheData );
  4362.   { Free the socket; auto calls WSACleanup }
  4363.   TempSocket.Free;
  4364. end;
  4365.  
  4366. { This method sets the progress output vector to the memo }
  4367. procedure TCCINetCCForm.ViewInEditWindow1Click(Sender: TObject);
  4368. begin
  4369.   { Set the vector }
  4370.   ProgressOutputVector := POV_MEMO;
  4371.   { Keep the menu options consistent }
  4372.   ViewInEditWindow1.Checked := true;
  4373.   ViewInStatusLine1.Checked := false;
  4374. end;
  4375.  
  4376. { This method sets the progress output vector to the status line }
  4377. procedure TCCINetCCForm.ViewInStatusLine1Click(Sender: TObject);
  4378. begin
  4379.   { Set the vector }
  4380.   ProgressOutputVector := POV_STAT;
  4381.   { Keep the menus consistent }
  4382.   ViewInEditWindow1.Checked := false;
  4383.   ViewInStatusLine1.Checked := true;
  4384. end;
  4385.  
  4386. procedure TCCINetCCForm.SaveToFile1Click(Sender: TObject);
  4387. begin
  4388.   { Set up the dialog parameters }
  4389.   OpenDialog1.Filename := ProgressFileName;
  4390.   OpenDialog1.Title := 'Select Filename for Progress File';
  4391.   OpenDialog1.Filter := 'Text Files|*.txt';
  4392.   { If the dialog is not cancelled then save and clear }
  4393.   if OpenDialog1.Execute then
  4394.   begin
  4395.     ProgressFileName := OpenDialog1.FileName;
  4396.     ProgressList.SaveToFile( ProgressFileName );
  4397.     ProgressList.Clear;
  4398.   end;
  4399. end;
  4400.  
  4401. procedure TCCINetCCForm.IPAddress1Click(Sender: TObject);
  4402. begin
  4403.   { Set up info dialog for IP Address getting }
  4404.   CCICInfoDlg.Caption := 'CC Internet Center -- Translate IP Address';
  4405.   CCICInfoDlg.Panel4.Visible := false;
  4406.   CCICInfoDlg.Panel6.Visible := false;
  4407.   CCICInfoDlg.Panel9.Visible := false;
  4408.   CCICInfoDlg.Panel8.Visible := false;
  4409.   CCICInfoDlg.BitBtn2.Visible := false;
  4410.   CCICInfoDlg.Button1.Caption := 'Get IP Address';
  4411.   CCICInfoDlg.Button2.Visible := false;
  4412.   CCICInfoDlg.Button3.Visible := false;
  4413.   CCICInfoDlg.Button4.Visible := false;
  4414.   CCICInfoDlg.Panel2.Caption := 'IP Addr Name:';
  4415.   CCICInfoDlg.Panel3.Caption := '    Dotted Dec:';
  4416.   CCICInfoDlg.Panel5.Caption := '           Binary:';
  4417.   CCICInfoDlg.Edit1.Text := '';
  4418.   CCICInfoDlg.Edit2.Text := '';
  4419.   CCICInfoDlg.Edit3.Text := '';
  4420.   { Set IP Address Mode }
  4421.   CCICInfoDlg.Tag := 1;
  4422.   { Show Modally to get the information }
  4423.   CCICInfoDlg.ShowModal;
  4424.   { Reset the info dialog to default conditions }
  4425.   CCICInfoDlg.Caption := 'CC Internet Command Center Information Dialog';
  4426.   CCICInfoDlg.Panel4.Visible := true;
  4427.   CCICInfoDlg.Panel6.Visible := true;
  4428.   CCICInfoDlg.Panel9.Visible := true;
  4429.   CCICInfoDlg.Panel8.Visible := true;
  4430.   CCICInfoDlg.BitBtn2.Visible := true;
  4431.   CCICInfoDlg.Button1.Caption := 'Anonymous Login';
  4432.   CCICInfoDlg.Button2.Visible := true;
  4433.   CCICInfoDlg.Button3.Visible := true;
  4434.   CCICInfoDlg.Button4.Visible := true;
  4435.   CCICInfoDlg.Panel2.Caption := '             Name:';
  4436.   CCICInfoDlg.Panel3.Caption := '    IP Address:';
  4437.   CCICInfoDlg.Panel5.Caption := ' User Name:';
  4438.   CCICInfoDlg.Edit1.Text := '';
  4439.   CCICInfoDlg.Edit2.Text := '';
  4440.   CCICInfoDlg.Edit3.Text := '';
  4441. end;
  4442.  
  4443. procedure TCCINetCCForm.FTP1Click(Sender: TObject);
  4444. begin
  4445.   { Set up the FTP Data displays }
  4446.   SetupFTPSiteLists;
  4447.   ListBox1.Clear;
  4448.   ListBox2.Clear;
  4449. end;
  4450.  
  4451. procedure TCCINetCCForm.FormResize(Sender: TObject);
  4452. begin
  4453.   { Use tag vector to determine what to do }
  4454.   case Tag of
  4455.     { if FTP , make sure two list boxes are same height }
  4456.     2 : begin
  4457.           Panel6.Height := (( Panel4.Height div 2 ) - 30 );
  4458.           Panel4.Width := 185;
  4459.         end;
  4460.     4 : begin
  4461.           Panel6.Height := 118;
  4462.           Panel4.Width := 250;
  4463.         end;
  4464.   end;
  4465. end;
  4466.  
  4467. procedure TCCINetCCForm.FTPSites1Click(Sender: TObject);
  4468. begin
  4469.   { Show Modally to get the information }
  4470.   CCICInfoDlg.ShowModal;
  4471. end;
  4472.  
  4473. procedure TCCINetCCForm.FTP3Click(Sender: TObject);
  4474. begin
  4475.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 1;
  4476.   CCICPrefsDlg.Tag := 2;
  4477.   CCICPrefsDlg.ShowModal;
  4478. end;
  4479.  
  4480. procedure TCCINetCCForm.ConnectToSite1Click(Sender: TObject);
  4481. var Counter_1 : Integer;
  4482. begin
  4483.   if Lowercase( PConnectionsRecord( TheFTPSiteList.Items[
  4484.    ComboBox1.ItemIndex ] )^.CUserName ) = 'anonymous' then
  4485.   begin
  4486.     for Counter_1 := 1 to TheAnonRedialVector do
  4487.     begin
  4488.       DoFTPConnection( PConnectionsRecord(
  4489.          TheFTPSiteList.Items[ ComboBox1.ItemIndex ] ));
  4490.       if TheFTPComponent.Connection_Established then exit;
  4491.     end;
  4492.   end
  4493.   else DoFTPConnection( PConnectionsRecord(
  4494.    TheFTPSiteList.Items[ ComboBox1.ItemIndex ] ));
  4495. end;
  4496.  
  4497. procedure TCCINetCCForm.Button1Click(Sender: TObject);
  4498. begin
  4499.   case Tag of
  4500.     2 : begin
  4501.           if not TheFTPComponent.Connection_Established then
  4502.            ConnectToSite1Click( Self ) else
  4503.            begin
  4504.              DoFTPDisconnect;
  4505.              TheFTPComponent.Connection_Established := false;
  4506.              DisableFTPMenus;
  4507.            end;
  4508.         end;
  4509.     4 : begin
  4510.           ConnectAndUpdate1Click( Self );
  4511.         end;
  4512.     5 : begin
  4513.           GetMarked1Click( Self );
  4514.         end;
  4515.     6 : begin
  4516.            CheckMail1Click( Self );
  4517.         end;
  4518.   end;
  4519. end;
  4520.  
  4521. procedure TCCINetCCForm.ViewasText1Click(Sender: TObject);
  4522. begin
  4523.   { Assume valid FTP component and have it send its text into the progress text}
  4524.   TheFTPComponent.GetRemoteDirectoryListingToMemo;
  4525. end;
  4526.  
  4527. procedure TCCINetCCForm.Disconnect1Click(Sender: TObject);
  4528. begin
  4529.   DoFTPDisconnect;
  4530.   DisableFTPMenus;
  4531. end;
  4532.  
  4533. procedure TCCINetCCForm.EnableFTPMenus;
  4534. begin
  4535.   Button1.Caption := 'Disconnect';
  4536.   ConnectToSite1.Enabled := false;
  4537.   Disconnect1.Enabled := true;
  4538.   Directory1.Enabled := true;
  4539.   UploadMarked1.Enabled := true;
  4540.   DownloadMarked1.Enabled := true;
  4541. end;
  4542.  
  4543. procedure TCCINetCCForm.DisableFTPMenus;
  4544. begin
  4545.   Button1.Caption := 'Connect';
  4546.   ConnectToSite1.Enabled := true;
  4547.   Disconnect1.Enabled := false;
  4548.   Directory1.Enabled := false;
  4549.   UploadMarked1.Enabled := false;
  4550.   DownloadMarked1.Enabled := false;
  4551.   FTP1.Enabled := true;
  4552.   UseNetNws1.Enabled := true;
  4553.   IPAddress1.Enabled := true;
  4554.   FTP2.Enabled := false;
  4555. end;
  4556.  
  4557. procedure TCCINetCCForm.EnableNNTPMenus;
  4558. begin
  4559.   Button1.Caption := 'Disconnect';
  4560.   ConnectAndUpdate1.Enabled := false;
  4561.   Disconnect2.Enabled := true;
  4562.   CheckNewNews1.Enabled := true;
  4563.   GetMarked1.Enabled := true;
  4564.   Article1.Enabled := true;
  4565.   Post1.Enabled := true;
  4566.   SubScribedNewsgroups1.Enabled := true;
  4567.   Trash1.Enabled := true;
  4568.   Headers1.Enabled := true;
  4569.   DownLoadActiveNewsGroups1.Enabled := true;
  4570. end;
  4571.  
  4572. procedure TCCINetCCForm.DisableNNTPMenus;
  4573. begin
  4574.   Button1.Caption := 'Connect';
  4575.   ConnectAndUpdate1.Enabled := True;
  4576.   Disconnect2.Enabled := false;
  4577.   CheckNewNews1.Enabled := false;
  4578.   GetMarked1.Enabled := false;
  4579.   Article1.Enabled := false;
  4580.   Post1.Enabled := false;
  4581.   SubScribedNewsgroups1.Enabled := false;
  4582.   Trash1.Enabled := false;
  4583.   Headers1.Enabled := false;
  4584.   DownLoadActiveNewsGroups1.Enabled := false;
  4585. end;
  4586.  
  4587. procedure TCCINetCCForm.ToDisplay1Click(Sender: TObject);
  4588. var Counter_1 : Integer;
  4589. begin
  4590.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4591.   begin
  4592.     if Listbox1.Selected[ Counter_1 ] then
  4593.     begin
  4594.       FileNameToXFer := ListBox1.Items[ Counter_1 ];
  4595.       TheFTPComponent.
  4596.        ReceiveASCIIRemoteFileToMemo( Listbox1.Items[ Counter_1 ] );
  4597.     end;
  4598.   end;
  4599. end;
  4600.  
  4601. procedure TCCINetCCForm.ToFile1Click(Sender: TObject);
  4602. var Counter_1 : Integer;
  4603.     W16Name   : String;
  4604. begin
  4605.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4606.   begin
  4607.     if Listbox1.Selected[ Counter_1 ] then
  4608.     begin
  4609.       FileNameToXFer := ListBox1.Items[ Counter_1 ];
  4610.       W16Name := TheFTPComponent.GetWin16Filename( FileNameToXFer );
  4611.       TheFTPComponent.
  4612.        ReceiveASCIIRemoteFile( Listbox1.Items[ Counter_1 ] , W16Name );
  4613.     end;
  4614.   end;
  4615. end;
  4616.  
  4617. procedure TCCINetCCForm.Binary2Click(Sender: TObject);
  4618. var Counter_1 : Integer;
  4619.     W16Name   : String;
  4620. begin
  4621.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4622.   begin
  4623.     if Listbox1.Selected[ Counter_1 ] then
  4624.     begin
  4625.       FileNameToXFer := ListBox1.Items[ Counter_1 ];
  4626.       W16Name := TheFTPComponent.GetWin16Filename( FileNameToXFer );
  4627.       TheFTPComponent.
  4628.        ReceiveBinaryRemoteFile( Listbox1.Items[ Counter_1 ] , W16Name );
  4629.     end;
  4630.   end;
  4631. end;
  4632.  
  4633. procedure TCCINetCCForm.Change1Click(Sender: TObject);
  4634. var TheDir : String;
  4635. begin
  4636.   if ListBox1.ItemIndex = -1 then exit;
  4637.   TheDir := ListBox1.Items[ ListBox1.ItemIndex ];
  4638.   if TheFTPComponent.SetRemoteDirectory( TheDir ) then
  4639.   begin
  4640.     TheFTPComponent.GetRemoteWorkingDirectory( TheDir ); 
  4641.     { Put up remote directory via PWD and strip quotes }
  4642.     Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4643.     { Get the listings of directories and exit OK }
  4644.     TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4645.   end;
  4646. end;
  4647.  
  4648. procedure TCCINetCCForm.ChangeLocal1Click(Sender: TObject);
  4649. var TheDir : String;
  4650. begin
  4651.   if ListBox2.ItemIndex = -1 then exit;
  4652.   TheDir := ListBox2.Items[ ListBox2.ItemIndex ];
  4653.   TheDir := TheFTPComponent.StripBrackets( TheDir );
  4654.   if TheDir = '..' then
  4655.   begin
  4656.     ChDir( TheDir );
  4657.   end
  4658.   else
  4659.   begin
  4660.     TheDir := ExpandFileName( TheDir );
  4661.     ChDir( TheDir );
  4662.   end;
  4663.   TheFTPComponent.GetLocalDirectoryAndListing( TheDir , Listbox2 );
  4664.   if Label5.Canvas.TextWidth( TheDir ) > Label5.Width then
  4665.    TheDir := TheFTPComponent.GetShortPathName( TheDir );
  4666.   Label5.Caption := TheDir;
  4667. end;
  4668.  
  4669. procedure TCCINetCCForm.ListBox1DblClick(Sender: TObject);
  4670. begin
  4671.   case Tag of
  4672.     2 : begin
  4673.           case DefaultDownLoadVector of
  4674.             1 : Binary2Click( Self );
  4675.             2 : ToFile1Click( Self );
  4676.             3 : Change1Click( Self );
  4677.           end;
  4678.         end;
  4679.   end;
  4680. end;
  4681.  
  4682. procedure TCCINetCCForm.ListBox2DblClick(Sender: TObject);
  4683. var WorkingString ,
  4684.     NumberString    : String;
  4685.     TheIDNumber     : Integer;
  4686.     TheNGARecord    : PNewsGroupArticleRecord;
  4687. begin
  4688.   case Tag of
  4689.     2 : begin
  4690.           case DefaultDownLoadVector of
  4691.             1 : Binary1Click( Self );
  4692.             2 : ASCII1Click( Self );
  4693.             3 : ChangeLocal1Click( Self );
  4694.           end;
  4695.         end;
  4696.     5 : begin
  4697.           if ListBox2.Tag <> 5 then exit;
  4698.           if ListBox2.ItemIndex = -1 then exit;
  4699.           WorkingString := ListBox2.Items[ ListBox2.ItemIndex ];
  4700.           NumberString := TheFTPComponent.StripBrackets( WorkingString );
  4701.           TheIDNumber := StrToInt( NumberString );
  4702.           TheNGARecord := PNewsGroupArticleRecord(
  4703.            TheNGArticlesList.Items[ TheIDNumber ] );
  4704.           if TheNGARecord^.NGADownloaded then
  4705.           begin
  4706.             Memo1.Clear;
  4707.             try
  4708.               Memo1.Lines.LoadFromFile( NewsPath + '\' + TheNGARecord^.NGAArtFileName );
  4709.             except
  4710.               MessageDlg( 'Article Too Large to Load! Use Write to View [' +
  4711.                TheNGARecord^.NGAArtFilename + '.',
  4712.                mtError,[mbOK],0);
  4713.               exit;
  4714.             end;
  4715.             Label1.Caption := 'Subject:';
  4716.             ComboBox1.Text := TheNGARecord^.NGASubject;
  4717.             TheNGARecord^.NGARead := true;
  4718.             WorkingString := ListBox2.Items[ ListBox2.ItemIndex ];
  4719.             WorkingString[ 3 ] := 'R';
  4720.             ListBox2.Items[ ListBox2.ItemIndex ] := WorkingString;
  4721.           end
  4722.           else
  4723.           begin
  4724.             MessageDlg( 'Article Not Downloaded!',mtError,[mbOK],0);
  4725.           end;
  4726.         end;
  4727.     6 : begin
  4728.           if ListBox2.ItemIndex = -1 then exit;
  4729.           WorkingString := PEMailMessageRecord(
  4730.            TheMBMessagesList.Items[ ListBox2.ItemIndex ] )^.MRFileName;
  4731.           PEMailMessageRecord(
  4732.            TheMBMessagesList.Items[ ListBox2.ItemIndex ] )^.MRRead := true;;
  4733.           WorkingString := MailPath + '\' + WorkingString;
  4734.           Memo1.Clear;
  4735.           try
  4736.             Memo1.Lines.LoadFromFile( WorkingString );
  4737.           except
  4738.             MessageDlg( 'Article Too Large to Load! Use Write to View.',
  4739.              mtError,[mbOK],0);
  4740.             exit;
  4741.           end;
  4742.           Label1.Caption := 'Subject:';
  4743.           ComboBox1.Text := PEMailMessageRecord(
  4744.            TheMBMessagesList.Items[ ListBox2.ItemIndex ] )^.MRMessageSubject;
  4745.           PopulateLB2WithMessageHeaders;
  4746.         end;
  4747.   end;
  4748. end;
  4749.  
  4750. procedure TCCINetCCForm.ASCII1Click(Sender: TObject);
  4751. var Counter_1 : Integer;
  4752.     TheDir    : String;
  4753. begin
  4754.   for Counter_1 := 0 to Listbox2.Items.Count - 1 do
  4755.   begin
  4756.     if Listbox2.Selected[ Counter_1 ] then
  4757.     begin
  4758.       FileNameToXFer := ListBox2.Items[ Counter_1 ];
  4759.       TheFTPComponent.
  4760.        SendASCIILocalFile( Listbox2.Items[ Counter_1 ] );
  4761.     end;
  4762.   end;
  4763.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4764.   { Put up remote directory via PWD and strip quotes }
  4765.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4766.   { Get the listings of directories and exit OK }
  4767.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4768. end;
  4769.  
  4770. procedure TCCINetCCForm.DeleteRemoteFiles1Click(Sender: TObject);
  4771. var Counter_1 : Integer;
  4772.     TheDir    : String;
  4773.     DoAll     : Boolean;
  4774.     TheResult : Integer;
  4775. begin
  4776.   DoAll := false;
  4777.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4778.   begin
  4779.     if Listbox1.Selected[ Counter_1 ] then
  4780.     begin
  4781.       if not DoAll then
  4782.       begin
  4783.         TheResult := MessageDlg( 'Delete Remote File ' +
  4784.          ListBox1.Items[ Counter_1 ] + ' ?',mtConfirmation,
  4785.           [mbYes,mbNo,mbCancel,mbAll],0 );
  4786.         case TheResult of
  4787.           mrYes : ;
  4788.           mrNo  : ;
  4789.           mrCancel : break;
  4790.           mrAll : begin
  4791.                     TheResult := mrYes;
  4792.                     DoAll := true;
  4793.                   end;
  4794.         end;
  4795.       end
  4796.       else TheResult := mrYes;
  4797.       if TheResult = mrYes then TheFTPComponent.
  4798.          DeleteRemoteFile( Listbox1.Items[ Counter_1 ] );
  4799.     end;
  4800.   end;
  4801.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4802.   { Put up remote directory via PWD and strip quotes }
  4803.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4804.   { Get the listings of directories and exit OK }
  4805.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4806. end;
  4807.  
  4808. procedure TCCINetCCForm.Binary1Click(Sender: TObject);
  4809. var Counter_1 : Integer;
  4810.     TheDir    : String;
  4811. begin
  4812.   for Counter_1 := 0 to Listbox2.Items.Count - 1 do
  4813.   begin
  4814.     if Listbox2.Selected[ Counter_1 ] then
  4815.     begin
  4816.       FileNameToXFer := ListBox2.Items[ Counter_1 ];
  4817.       TheFTPComponent.
  4818.        SendBinaryLocalFile( Listbox2.Items[ Counter_1 ] );
  4819.     end;
  4820.   end;
  4821.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4822.   { Put up remote directory via PWD and strip quotes }
  4823.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4824.   { Get the listings of directories and exit OK }
  4825.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4826. end;
  4827.  
  4828. procedure TCCINetCCForm.Delete3Click(Sender: TObject);
  4829. var Counter_1 : Integer;
  4830.     TheDir    : String;
  4831. begin
  4832.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4833.   begin
  4834.     if Listbox1.Selected[ Counter_1 ] then
  4835.     begin
  4836.       if ListBox1.Items[ Counter_1 ] <> '..' then
  4837.        TheFTPComponent.
  4838.         DeleteRemoteDirectory( Listbox1.Items[ Counter_1 ] );
  4839.     end;
  4840.   end;
  4841.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4842.   { Put up remote directory via PWD and strip quotes }
  4843.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4844.   { Get the listings of directories and exit OK }
  4845.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4846. end;
  4847.  
  4848. procedure TCCINetCCForm.Create1Click(Sender: TObject);
  4849. var TheDir : String;
  4850. begin
  4851.   OpenDialog1.Filename := '*.*';
  4852.   OpenDialog1.Title := 'Enter Remote Directory Name';
  4853.   if OpenDialog1.Execute then
  4854.   begin
  4855.     TheFTPComponent.
  4856.      CreateRemoteDirectory( ExtractFileName( OpenDialog1.FileName ));
  4857.     TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4858.     { Put up remote directory via PWD and strip quotes }
  4859.     Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4860.     { Get the listings of directories and exit OK }
  4861.     TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4862.   end;
  4863. end;
  4864.  
  4865. procedure TCCINetCCForm.ListBox1Click(Sender: TObject);
  4866. var TheNGRecord : PNewsGroupRecord;
  4867.     TheMBRecord : PEMailMailboxRecord;
  4868. begin
  4869.   case ListBox1.Tag of
  4870.     5 : begin
  4871.           if ListBox1.ItemIndex = -1 then exit;
  4872.           TheNGRecord :=
  4873.            PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  4874.           TheNGArticlesList := TList( TheNGRecord^.GLTag );
  4875.           PopulateLB2WithArticleHeaders;
  4876.           ComboBox1.ItemIndex := ListBox1.ItemIndex;
  4877.         end;
  4878.     6 : begin
  4879.           if ListBox1.ItemIndex = -1 then exit;
  4880.           TheMBRecord :=
  4881.            PEMailMailboxRecord( TheEMailMailboxList.Items[ ListBox1.ItemIndex ] );
  4882.           TheMBMessagesList := TList( TheMBRecord^.MBLTag );
  4883.           PopulateLB2WithMessageHeaders;
  4884.         end;
  4885.   end;
  4886. end;
  4887.  
  4888. procedure TCCINetCCForm.UsenetNws1Click(Sender: TObject);
  4889. begin
  4890.   if TheFTPComponent.Connection_Established then
  4891.   begin
  4892.     MessageDlg( 'Must disconnect from current FTP session first!',
  4893.      mtError,[mbOK],0);
  4894.     exit;
  4895.   end;
  4896.   { Show The NNTP servers display }
  4897.   ListBox1.Clear;
  4898.   ListBox2.Clear;
  4899.   SetupNNTPSiteLists;
  4900.   NewsGroupListLoaded := false;
  4901.   SetupNNTPServersInfoDisplay;
  4902. end;
  4903.  
  4904. procedure TCCINetCCForm.Disconnect2Click(Sender: TObject);
  4905. begin
  4906.   SaveNNTPNewsGroupLists;
  4907.   DoNNTPDisconnect;
  4908.   DisableNNTPMenus;
  4909.   ListBox1.Clear;
  4910.   ListBox2.Clear;
  4911. end;
  4912.  
  4913. procedure TCCINetCCForm.News2Click(Sender: TObject);
  4914. begin
  4915.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 2;
  4916.   CCICPrefsDlg.Tag := 4;
  4917.   CCICPrefsDlg.ShowModal;
  4918. end;
  4919.  
  4920. procedure TCCINetCCForm.ConnectandUpdate1Click(Sender: TObject);
  4921. begin
  4922.   DoNNTPConnection( PConnectionsRecord(
  4923.      TheNewsServerList.Items[ ComboBox1.ItemIndex ] ));
  4924.   if TheNNTPComponent.Connection_Established then
  4925.   begin
  4926.     SetupNNTPNewsGroupLists;
  4927.     if NewsInitialUpdateVector = 1 then
  4928.     begin { Update all active newsgroups }
  4929.       TheNNTPComponent.CheckAllNewNews;
  4930.     end;
  4931.     { Bring up the files with current NG information }
  4932.     SetupNewsGroupListboxes;
  4933.   end;
  4934. end;
  4935.  
  4936. procedure TCCINetCCForm.CheckNewNews1Click(Sender: TObject);
  4937. begin
  4938.   TheNNTPComponent.CheckAllNewNews;
  4939.   SetupNewsGroupListboxes;
  4940. end;
  4941.  
  4942. procedure TCCINetCCForm.NewsServers1Click(Sender: TObject);
  4943. begin
  4944.   { Reset display to NNTP Servers }
  4945.   SetupNNTPServersInfoDisplay;
  4946.   { Show Modally to get the information }
  4947.   CCICInfoDlg.ShowModal;
  4948. end;
  4949.  
  4950. procedure TCCINetCCForm.SubscribedNewsgroups1Click(Sender: TObject);
  4951. begin
  4952.   { Reset display to Usenet Newsgroups }
  4953.   SetupNNTPNewsGroupsInfoDisplay;
  4954.   { Show Modally to get the information }
  4955.   CCICInfoDlg.ShowModal;
  4956.   TheNNTPComponent.CheckAllNewNews;
  4957.   SetupNewsGroupListboxes;
  4958. end;
  4959.  
  4960. procedure TCCINetCCForm.RetrieveMarked1Click(Sender: TObject);
  4961. var Counter_1   : Integer;
  4962.     TheNGRecord : PNewsGroupRecord;
  4963. begin
  4964.   for Counter_1 := 0 to ListBox1.Items.Count - 1 do
  4965.   begin
  4966.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  4967.     if (( TheNGRecord^.GSubscribed ) and ( ListBox1.Selected[ Counter_1 ] )) then
  4968.     begin
  4969.       TheNNTPComponent.GetAllArticleHeaders( TheNGRecord );
  4970.     end;
  4971.   end;
  4972.   SetupNewsGroupListboxes;
  4973. end;
  4974.  
  4975. procedure TCCINetCCForm.RetrieveAll1Click(Sender: TObject);
  4976. var Counter_1   : Integer;
  4977.     TheNGRecord : PNewsGroupRecord;
  4978. begin
  4979.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  4980.   begin
  4981.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  4982.     if TheNGRecord^.GSubscribed then
  4983.     begin
  4984.       TheNNTPComponent.GetAllArticleHeaders( TheNGRecord );
  4985.     end;
  4986.   end;
  4987.   SetupNewsGroupListboxes;
  4988. end;
  4989.  
  4990. procedure TCCINetCCForm.GetMarked1Click(Sender: TObject);
  4991. var TheNGRecord : PNewsGroupRecord;
  4992. begin
  4993.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  4994.   TheNNTPComponent.DownloadAllMarkedArticleListings( TheNGRecord , ListBox2 );
  4995.   SetupNewsGroupListboxes;
  4996. end;
  4997.  
  4998. procedure TCCINetCCForm.NewArticle1Click(Sender: TObject);
  4999. begin
  5000.   if ListBox1.ItemIndex = -1 then exit;
  5001.   Memo1.Clear;
  5002.   TheNNTPComponent.SetNewsHeaders( Memo1 , ListBox1.ItemIndex );
  5003. end;
  5004.  
  5005. procedure TCCINetCCForm.FollowupArticle1Click(Sender: TObject);
  5006. begin
  5007.   if ListBox1.ItemIndex = -1 then exit;
  5008.   if ListBox2.ItemIndex = -1 then exit;
  5009.   Memo1.Clear;
  5010.   TheNNTPComponent.SetFUNewsHeaders( Memo1              ,
  5011.                                      ListBox1.ItemIndex ,
  5012.                                      ListBox2.ItemIndex   );
  5013. end;
  5014.  
  5015. procedure TCCINetCCForm.PutinQueue1Click(Sender: TObject);
  5016. var TheNGRecord : PNewsGroupRecord;
  5017.     TheNGARecord : PNewsGroupArticleRecord;
  5018.     WorkingList : TList;
  5019.     WorkingFilename : String;
  5020.     Holdingposition : Integer;
  5021. begin
  5022.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5023.   WorkingList := TList( TheNGRecord^.GLTag );
  5024.   New( TheNGARecord );
  5025.   with TheNGARecord^ do
  5026.   begin
  5027.     NGAGroupname   := TheNGRecord^.GRealName;
  5028.     NGASubject     := TheNNTPComponent.GetHeaderSubject( TStringList( Memo1.Lines ));
  5029.     NGANumber      := TheNGRecord^.GHighestAvailable + WorkingList.Count;
  5030.     NGADownloaded  := true;
  5031.     NGASender      := 'CIUPKC158';
  5032.     NGARead        := false;
  5033.     NGAPosted      := false;
  5034.     WorkingFileName := 'AR' + IntToStr( NGANumber );
  5035.     if Length( WorkingFileName ) > 8 then
  5036.      WorkingFileName := Copy( WorkingFileName ,1 , 8 );
  5037.     WorkingFileName := WorkingFileName + '.' + IntToStr( TheNGRecord^.GIDNumber );
  5038.     NGAArtFileName := WorkingFileName;
  5039.   end;
  5040.   WorkingList.Add( TheNGARecord );
  5041.   Memo1.Lines.SaveToFile( NewsPath + '\' + WorkingFileName );
  5042.   HoldingPosition := ListBox1.itemindex;
  5043.   SetupNewsGroupListboxes;
  5044.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ HoldingPosition ] );
  5045.   TheNGArticlesList := TList( TheNGRecord^.GLTag );
  5046.   PopulateLB2WithArticleHeaders;
  5047. end;
  5048.  
  5049. procedure TCCINetCCForm.CurrentArticle1Click(Sender: TObject);
  5050. var TheNGARecord : PNewsGroupArticleRecord;
  5051.     TheNGRecord  : PNewsGroupRecord;
  5052.     HP : Integer;
  5053. begin
  5054.   HP := ListBox1.itemindex;
  5055.   PutInQueue1Click( Self );
  5056.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ HP ] );
  5057.   TheNGArticlesList := TList( TheNGRecord^.GLTag );
  5058.   TheNGARecord := PNewsGroupArticleRecord( TheNGArticlesList.Items[ TheNGArticlesList.Count - 1 ] );
  5059.   TheNNTPComponent.UploadArticleListing( TheNGARecord );
  5060. end;
  5061.  
  5062. procedure TCCINetCCForm.EntireQueue1Click(Sender: TObject);
  5063. var TheNGRecord : PNewsGroupRecord;
  5064. begin
  5065.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5066.   TheNNTPComponent.UploadAllArticleListings( TheNGRecord );
  5067. end;
  5068.  
  5069. procedure TCCINetCCForm.AllReadArticles1Click(Sender: TObject);
  5070. var TheNGRecord : PNewsGroupRecord;
  5071. begin
  5072.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5073.   TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5074.   SetupNewsGroupListboxes;
  5075. end;
  5076.  
  5077. procedure TCCINetCCForm.AllMarkedArticles1Click(Sender: TObject);
  5078. var TheNGRecord : PNewsGroupRecord;
  5079.     TheNGARecord : PNewsGroupArticleRecord;
  5080.     WorkingList : TList;
  5081.     Counter_1 : Integer;
  5082. begin
  5083.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5084.   WorkingList := TList( TheNGRecord^.GLTag );
  5085.   for Counter_1 := 0 to ListBox2.Items.Count - 1 do
  5086.   begin
  5087.     if ListBox2.Selected[ Counter_1 ] then
  5088.     begin
  5089.       TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_1 ] );
  5090.       TheNGARecord^.NGARead := true;
  5091.     end;
  5092.   end;
  5093.   TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5094.   SetupNewsGroupListboxes;
  5095. end;
  5096.  
  5097. procedure TCCINetCCForm.AllAvailableArticles1Click(Sender: TObject);
  5098. var TheNGRecord : PNewsGroupRecord;
  5099.     TheNGARecord : PNewsGroupArticleRecord;
  5100.     WorkingList : TList;
  5101.     Counter_1  : Integer;
  5102. begin
  5103.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5104.   WorkingList := TList( TheNGRecord^.GLTag );
  5105.   for Counter_1 := 0 to ListBox2.Items.Count - 1 do
  5106.   begin
  5107.     TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_1 ] );
  5108.     TheNGARecord^.NGARead := true;
  5109.   end;
  5110.   TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5111.   SetupNewsGroupListboxes;
  5112. end;
  5113.  
  5114. procedure TCCINetCCForm.DownloadActiveNewsgroups1Click(Sender: TObject);
  5115. begin
  5116.   if MessageDlg( 'This will take considerable time. Proceed?',mtConfirmation,
  5117.    mbYesNoCancel,0) = mrYes then
  5118.   begin
  5119.     Memo1.Clear;
  5120.     TheNNTPComponent.GetListofAvailableNewsGroups;
  5121.   end;
  5122. end;
  5123.  
  5124. procedure TCCINetCCForm.UUEncode1Click(Sender: TObject);
  5125. begin
  5126.   OpenDialog1.Filename := '*.*';
  5127.   OpenDialog1.Title := 'Select File to UUENCODE';
  5128.   if OpenDialog1.Execute then
  5129.   begin
  5130.     TheUUObject.SetInputFileName( OpenDialog1.FileName );
  5131.     TheUUObject.EncodeCurrentInputs;
  5132.   end;
  5133. end;
  5134.  
  5135. procedure TCCINetCCForm.Load1Click(Sender: TObject);
  5136. var Memo2 : TMemo;
  5137.     Counter_1 : Integer;
  5138. begin
  5139.   OpenDialog1.Filename := '*.txt';
  5140.   OpenDialog1.Title := 'Select File to load into Memo';
  5141.   if OpenDialog1.Execute then
  5142.   begin
  5143.     Memo2 := TMemo.Create( Self );
  5144.     Memo2.Parent := Self;
  5145.     Memo2.Visible := false;
  5146.     Memo2.Width := Memo1.Width;
  5147.     Memo2.Height := Memo1.Height;
  5148.     Memo2.Lines.LoadFromFile( OpenDialog1.FileName );
  5149.     for Counter_1 := 0 to Memo2.Lines.Count - 1 do
  5150.      Memo1.Lines.Add( Memo2.Lines[ Counter_1 ] );
  5151.     Memo2.Free;
  5152.   end;
  5153. end;
  5154.  
  5155. procedure TCCINetCCForm.Save1Click(Sender: TObject);
  5156. begin
  5157.   SaveDialog1.Filename := '*.txt';
  5158.   SaveDialog1.Title := 'Select File to Save Memo to';
  5159.   if OpenDialog1.Execute then
  5160.   begin
  5161.     Memo1.Lines.SaveToFile( SaveDialog1.FileName );
  5162.   end;
  5163. end;
  5164.  
  5165. procedure TCCINetCCForm.EMail1Click(Sender: TObject);
  5166. begin
  5167.   if TheFTPComponent.Connection_Established then
  5168.   begin
  5169.     MessageDlg( 'Must disconnect from current FTP session first!',
  5170.      mtError,[mbOK],0);
  5171.     exit;
  5172.   end;
  5173.   if TheNNTPComponent.Connection_Established then
  5174.   begin
  5175.     MessageDlg( 'Must disconnect from current NNTP session first!',
  5176.      mtError,[mbOK],0);
  5177.     exit;
  5178.   end;
  5179.   { Show The POP3SMTP servers display }
  5180.   ListBox1.Clear;
  5181.   ListBox2.Clear;
  5182.   SetupEMailServerStatus;
  5183.   EnablePOP3SMTPMenus;
  5184.   SetupEMailServersInfoDisplay;
  5185. end;
  5186.  
  5187. procedure TCCINetCCForm.CheckMail1Click(Sender: TObject);
  5188. begin
  5189.   WhichServer := ComboBox1.ItemIndex + 1;
  5190.   if not EMailLoaded then
  5191.   begin
  5192.     LoadEMailMailBoxFile( WhichServer );
  5193.     LoadEMailCorrespondentsFile;
  5194.     EmailLoaded := true;
  5195.   end;
  5196.   DoPOP3Connection( TheEMailServerList.Items[ WhichServer - 1 ] );
  5197.   ThePOP3SMTPComponent.DownloadAllMessageListings(
  5198.    PEMailMailBoxRecord( TheEMailMailboxList.Items[ 0 ] ));
  5199.   ThePOP3SMTPComponent.POP3Disconnect;
  5200.   SetupEMailListBoxes;
  5201. end;
  5202.  
  5203. procedure TCCINetCCForm.MailServers1Click(Sender: TObject);
  5204. begin
  5205.   SetupEmailServersInfoDisplay;
  5206.   CCICInfoDlg.ShowModal;
  5207. end;
  5208.  
  5209. procedure TCCINetCCForm.EMail3Click(Sender: TObject);
  5210. begin
  5211.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 0;
  5212.   CCICPrefsDlg.Tag := 6;
  5213.   CCICPrefsDlg.ShowModal;
  5214. end;
  5215.  
  5216. procedure TCCINetCCForm.Paths1Click(Sender: TObject);
  5217. begin
  5218.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 3;
  5219.   CCICPrefsDlg.Tag := 3;
  5220.   CCICPrefsDlg.ShowModal;
  5221. end;
  5222.  
  5223. procedure TCCINetCCForm.ExitEMailRequired1Click(Sender: TObject);
  5224. begin
  5225.   if not ThePOP3SMTPComponent.Connection_Established then exit;
  5226.   DoPOP3SMTPDisconnect;
  5227.   SaveEMailMailBoxFile( WhichServer );
  5228.   SaveEMailCorrespondentsFile;
  5229.   DisablePOP3SMTPMenus;
  5230.   EMailLoaded := false;
  5231. end;
  5232.  
  5233. procedure TCCINetCCForm.Cut1Click(Sender: TObject);
  5234. begin
  5235.   Memo1.CutToClipboard;
  5236. end;
  5237.  
  5238. procedure TCCINetCCForm.Copy1Click(Sender: TObject);
  5239. begin
  5240.   Memo1.CopyToClipboard;
  5241. end;
  5242.  
  5243. procedure TCCINetCCForm.CopytoFile1Click(Sender: TObject);
  5244. var TempMemo : TMemo;
  5245. begin
  5246.   TempMemo := TMemo.Create( self );
  5247.   TempMemo.parent := self;
  5248.   Tempmemo.Visible := false;
  5249.   TempMemo.Width := Memo1.Width;
  5250.   TempMemo.Height := Memo1.Height;
  5251.   Memo1.CopyToClipboard;
  5252.   TempMemo.PasteFromClipboard;
  5253.   SaveDialog1.Filename := '*.TXT';
  5254.   SaveDialog1.Title := 'Select File to Save To';
  5255.   if SaveDialog1.Execute then TempMemo.Lines.SaveToFile( SaveDialog1.Filename );
  5256.   TempMemo.Free;
  5257. end;
  5258.  
  5259. procedure TCCINetCCForm.Paste1Click(Sender: TObject);
  5260. begin
  5261.   Memo1.PasteFromClipboard;
  5262. end;
  5263.  
  5264. procedure TCCINetCCForm.PastefromFile1Click(Sender: TObject);
  5265. var TempMemo : TMemo;
  5266. begin
  5267.   TempMemo := TMemo.Create( self );
  5268.   TempMemo.parent := self;
  5269.   Tempmemo.Visible := false;
  5270.   TempMemo.Width := Memo1.Width;
  5271.   TempMemo.Height := Memo1.Height;
  5272.   OpenDialog1.Filename := '*.*';
  5273.   OpenDialog1.Title := 'Select File to Paste From';
  5274.   if OpenDialog1.Execute then TempMemo.Lines.LoadFromFile( OpenDialog1.Filename );
  5275.   TempMemo.SelectAll;
  5276.   TempMemo.CopyToClipboard;
  5277.   Memo1.PasteFromClipboard;
  5278.   TempMemo.Free;
  5279. end;
  5280.  
  5281. procedure TCCINetCCForm.SpeedButton5Click(Sender: TObject);
  5282. begin
  5283.   case Tag of
  5284.     5 : AllMarkedArticles1Click( Self );
  5285.   end;
  5286. end;
  5287.  
  5288. procedure TCCINetCCForm.SpeedButton1Click(Sender: TObject);
  5289. begin
  5290.   case Tag of
  5291.     5 : begin
  5292.           if ListBox2.Items.Count = 0 then exit;
  5293.           Listbox2.multiselect := false;
  5294.           If ListBox2.ItemIndex = -1 then ListBox2.ItemIndex := 0;
  5295.           ListBox2.ItemIndex := Listbox2.ItemIndex - 1;
  5296.           if ListBox2.Itemindex < 0 then
  5297.            Listbox2.Itemindex := ListBox2.Items.Count - 1;
  5298.           ListBox2DblClick( Self );
  5299.           ListBox2.Multiselect := true;
  5300.           ListBox2.SetFocus;
  5301.         end;
  5302.   end;
  5303. end;
  5304.  
  5305. procedure TCCINetCCForm.SpeedButton2Click(Sender: TObject);
  5306. begin
  5307.   case Tag of
  5308.     5 : begin
  5309.           if ListBox2.Items.Count = 0 then exit;
  5310.           ListBox2.MultiSelect := false;
  5311.           If ListBox2.ItemIndex = -1 then ListBox2.ItemIndex := 0;
  5312.           ListBox2.ItemIndex := Listbox2.ItemIndex + 1;
  5313.           if ListBox2.Itemindex > ListBox2.Items.Count - 1 then
  5314.            Listbox2.Itemindex := 0;
  5315.           ListBox2DblClick( Self );
  5316.           ListBox2.MultiSelect := true;
  5317.           ListBox2.SetFocus;
  5318.         end;
  5319.   end;
  5320. end;
  5321.  
  5322. procedure TCCINetCCForm.ListBox2Click(Sender: TObject);
  5323. var TheWorkingList : TList;
  5324.     TheNGARecord : PNewsGroupArticleRecord;
  5325.     TheNGRecord : PNewsGroupRecord;
  5326.     TheWorkingName : String;
  5327. begin
  5328.   if ListBox2.Tag = 9 then
  5329.   begin
  5330.     TheNGRecord :=
  5331.      PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5332.     TheWorkingList := TList( TheNGRecord^.GLTag );
  5333.     TheNGARecord := PNewsGroupArticleRecord(
  5334.      TheWorkingList.Items[ ListBox2.ItemIndex ] );
  5335.     TheWorkingName := NewsPath + '\' + TheNGARecord^.NGAArtFileName;
  5336.     TheUUDecodeList.Add( TheWorkingName );
  5337.     exit;
  5338.   end;
  5339.   case Tag of
  5340.     5 : begin
  5341.           If ListBox2.Items.Count = 0 then exit;
  5342.           ComboBox1.Text := ListBox2.Items[ ListBox2.ItemIndex ];
  5343.         end;
  5344.   end;
  5345. end;
  5346.  
  5347. procedure TCCINetCCForm.AbortNewsgroupDownload1Click(Sender: TObject);
  5348. begin
  5349.   GlobalAbortedFlag := true;
  5350. end;
  5351.  
  5352. procedure TCCINetCCForm.Marked1Click(Sender: TObject);
  5353. var Counter_1,
  5354.     Counter_2   : Integer;
  5355.     TheNGRecord : PNewsGroupRecord;
  5356.     TheNGARecord : PNewsGroupArticleRecord;
  5357.     WorkingList : TList;
  5358. begin
  5359.   for Counter_1 := 0 to ListBox1.Items.Count - 1 do
  5360.   begin
  5361.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  5362.     if (( TheNGRecord^.GSubscribed ) and ( ListBox1.Selected[ Counter_1 ] )) then
  5363.     begin
  5364.       WorkingList := TList( TheNGRecord^.GLTag );
  5365.       for Counter_2 := 0 to ListBox2.Items.Count - 1 do
  5366.       begin
  5367.         TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_2 ] );
  5368.         TheNGARecord^.NGARead := true;
  5369.       end;
  5370.       TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5371.       TheNGRecord^.GLowest := TheNGRecord^.GHighestAvailable;
  5372.       TheNGRecord^.GHighest := TheNGRecord.GLowest;
  5373.       TheNGRecord^.GTotalNew := 0;
  5374.       TheNGRecord^.GTotalArticles := 0;
  5375.     end;
  5376.   end;
  5377.   SetupNewsGroupListboxes;
  5378. end;
  5379.  
  5380. procedure TCCINetCCForm.All1Click(Sender: TObject);
  5381. var Counter_1,
  5382.     Counter_2   : Integer;
  5383.     TheNGRecord : PNewsGroupRecord;
  5384.     TheNGARecord : PNewsGroupArticleRecord;
  5385.     WorkingList : TList;
  5386. begin
  5387.   for Counter_1 := 0 to ListBox1.Items.Count - 1 do
  5388.   begin
  5389.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  5390.     if TheNGRecord^.GSubscribed then
  5391.     begin
  5392.       WorkingList := TList( TheNGRecord^.GLTag );
  5393.       for Counter_2 := 0 to ListBox2.Items.Count - 1 do
  5394.       begin
  5395.         TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_2 ] );
  5396.         TheNGARecord^.NGARead := true;
  5397.       end;
  5398.       TheNGRecord^.GLowest := TheNGRecord^.GHighestAvailable;
  5399.       TheNGRecord^.GHighest := TheNGRecord.GLowest;
  5400.       TheNGRecord^.GTotalNew := 0;
  5401.       TheNGRecord^.GTotalArticles := 0;
  5402.       TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5403.     end;
  5404.   end;
  5405.   SetupNewsGroupListboxes;
  5406. end;
  5407.  
  5408. procedure TCCINetCCForm.File1Click(Sender: TObject);
  5409. begin
  5410.   OpenDialog1.Filename := '*.uue';
  5411.   OpenDialog1.Filter := 'UUEncode Files|*.uue|All Files *.*';
  5412.   OpenDialog1.Title := 'Select File To Decode';
  5413.   if OpenDialog1.Execute then
  5414.   begin
  5415.     TheUUObject.SetInputFileName( OpenDialog1.FileName );
  5416.     TheUUObject.SetMultifileVector( CMV_SINGLE );
  5417.     TheUUObject.Decode;
  5418.   end;
  5419. end;
  5420.  
  5421. procedure TCCINetCCForm.SelectedArticle1Click(Sender: TObject);
  5422. var TheWorkingList : TList;
  5423.     TheNGARecord : PNewsGroupArticleRecord;
  5424.     TheNGRecord : PNewsGroupRecord;
  5425.     TheWorkingName : String;
  5426. begin
  5427.   TheNGRecord :=
  5428.    PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5429.   TheWorkingList := TList( TheNGRecord^.GLTag );
  5430.   TheNGARecord := PNewsGroupArticleRecord(
  5431.    TheWorkingList.Items[ ListBox2.ItemIndex ] );
  5432.   TheWorkingName := NewsPath + '\' + TheNGARecord^.NGAArtFileName;
  5433.   TheUUObject.SetInputFileName( TheWorkingName );
  5434.   TheUUObject.SetMultifileVector( CMV_SINGLE );
  5435.   TheUUObject.Decode;
  5436. end;
  5437.  
  5438. procedure TCCINetCCForm.SelectMultipleArticles1Click(Sender: TObject);
  5439. begin
  5440.   { Set tag so that listbox knows to keep track of hits}
  5441.   ListBox2.Tag := 9;
  5442.   ListBox2.MultiSelect := false;
  5443.   TheUUDecodeList := TStringList.Create;
  5444. end;
  5445.  
  5446. procedure TCCINetCCForm.DecodeSelections1Click(Sender: TObject);
  5447. begin
  5448.   ListBox2.Tag := 5;
  5449.   ListBox2.MultiSelect := True;
  5450.   if TheUUDecodeList.Count = 0 then exit;
  5451.   TheUUObject.SetMultipleFilesList( TheUUDecodeList );
  5452.   TheUUObject.SetMultifileVector( CMV_MULTI );
  5453.   TheUUObject.Decode;
  5454.   TheUUDecodeList.Free;
  5455. end;
  5456.  
  5457. procedure TCCINetCCForm.SpeedButton4Click(Sender: TObject);
  5458. begin
  5459.   case Tag of
  5460.     5 : begin
  5461.           SelectedArticle1Click( Self );
  5462.         end;
  5463.   end;
  5464. end;
  5465.  
  5466. end.
  5467.  
  5468.